So by checking the last bit, I can know, whenever variable went into negative world, right?
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
I came into another issue.
I have font array in EEPROM, and need to set offset for reading it. Depending on charset, this offset can be negative and positive.
So I have to do it in a way like this:
if langvar[x]=0 then
Y=(topline[x])*8+OFS
if langvar[x]=1 then
Y=(topline[x])*8-OFS
Can these two joined into single operation somehow?
IoannisCode:if langvar[x]=0 then Y=(topline[x])*8+OFS else Y=(topline[x])*8-OFS endif
No, I meant changing the value of OFS in the way, that addition will cause actual subtraction, due to overflow.
Bookmarks