what does get bad mean ?But if ADC value gets below 150, then things get bad.
show your code
what does get bad mean ?But if ADC value gets below 150, then things get bad.
show your code
Variable value should go to negative, but since we have no negative, it goes into 65xxx range![]()
only if you interpret it incorrectly and ignore the sign bitVariable value should go to negative, but since we have no negative, it goes into 65xxx range
show your code
Warning I'm not a teacher
So by checking the last bit, I can know, whenever variable went into negative world, right?
That is what post #3 says. Henrik explained it well.
Ioannis
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.
its called two's compliment , no magic involved
https://en.wikipedia.org/wiki/Two%27s_complement
Warning I'm not a teacher
Bookmarks