mellis
Member
Mountain out of a molehill
Elmatador,
I think you should look up twos complement on Wikipedia. The explanation is pretty good.
Like I said in my previous post, there is no conversion from integer representation to twos complement. Twos complement *IS* the normal method of representing a signed integer. And, the "twos complement" part only applies to the representation of negative numbers.
Your specific examples in 16-bit format:
200 = 0000 0000 1100 1000 or Hex 00C8
-40 = 1111 1111 1101 1000 or Hex FFD8
This is normal, you put these patterns in a 16-bit integer and the PLC will interpret them as 200 and -40.
Now if you considered the bit pattern for a 16-bit -40 to be unsigned the value in decimal would be 65496. The only difference is how you interpret the bit pattern. If the high bit is on, you have to know if you are looking at a signed or unsigned number to know what it means.
Elmatador,
I think you should look up twos complement on Wikipedia. The explanation is pretty good.
Like I said in my previous post, there is no conversion from integer representation to twos complement. Twos complement *IS* the normal method of representing a signed integer. And, the "twos complement" part only applies to the representation of negative numbers.
Your specific examples in 16-bit format:
200 = 0000 0000 1100 1000 or Hex 00C8
-40 = 1111 1111 1101 1000 or Hex FFD8
This is normal, you put these patterns in a 16-bit integer and the PLC will interpret them as 200 and -40.
Now if you considered the bit pattern for a 16-bit -40 to be unsigned the value in decimal would be 65496. The only difference is how you interpret the bit pattern. If the high bit is on, you have to know if you are looking at a signed or unsigned number to know what it means.