Discussion:
Reading 65531, actual value -5
(too old to reply)
Sonnich Jensen
2015-10-07 08:44:32 UTC
Permalink
Hi all

I cannot remember the word for this technique.

Some thing sends me numbers:
5 - is 5
65531 - is -5 - "negated".

Is there an easy way to transform these?
mick
2015-10-07 09:10:23 UTC
Permalink
Post by Sonnich Jensen
Hi all
I cannot remember the word for this technique.
5 - is 5
65531 - is -5 - "negated".
Is there an easy way to transform these?
2's Complement.

http://www.exploringbinary.com/twos-complement-converter/

mick


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Sonnich Jensen
2015-10-07 13:35:53 UTC
Permalink
Post by Sonnich Jensen
Hi all
I cannot remember the word for this technique.
5 - is 5
65531 - is -5 - "negated".
Is there an easy way to transform these?
This is what I want looking for:

byte[] data = new byte[2];
data[0] = 0xFB;
data[1] = 0xFF;
short value = System.BitConverter.ToInt16(data, 0);
Arne Vajhøj
2015-10-08 01:46:38 UTC
Permalink
Post by Sonnich Jensen
Post by Sonnich Jensen
5 - is 5
65531 - is -5 - "negated".
Is there an easy way to transform these?
byte[] data = new byte[2];
data[0] = 0xFB;
data[1] = 0xFF;
short value = System.BitConverter.ToInt16(data, 0);
(short)((data[1] << 8) | data[0]);

should also do it, but BitConverter.ToInt16 is more
readable.

Arne

Continue reading on narkive:
Loading...