Whether signed or unsigned, 0 = 0.
With an Unsigned BYTE (let's start simple), the range is 0 to 255. From 255, add 1 and you get 0 again, as the BYTE rolls over.
With a Signed BYTE, the range is -128 to +127. Think in terms of binary: 127d = %0111 1111. Make sense so far?
Working with a Signed BYTE, if you calculate: "0 - 1 =", you get %1111 1111 which equals -1.
With an Unsigned BYTE, if you calculate: "0 - 1 =" you still get %1111 1111, but it equals 255.
Think about this for Signed Variables:
0d = %0000 0000
1d = %0000 0001
-1d = %1111 1111
-2d = %1111 1110
Sometimes just looking at the representations enables the light bulb to turn on.
Now if we're working at the 16-bit WORD level:
0d = %0000 0000 0000 0000
1d = %0000 0000 0000 0001
-1d = %1111 1111 1111 1111
-2d = %1111 1111 1111 1110
See the trend?? I hope this helps you figure some things out.




Bookmarks