
|
INFO - FAQ - CC2-Forum - CCPro-Forum |
|
||
|
> > But the last few quoted comments make me curious. In English they mean "if negative, print "-" and invert the number" (invert meaning to switch the sign). Yet for a -32768 stored in two bytes as a 2's complement, there is no way to invert it, since there is no positive 32768 which can be represented in two bytes in 2's complement. As we all know two bytes in 2's complement have a range from -32768 (0x8000) to 32767 (0x7ffff). > > > > I think you are making a thinking error ;). Am I? > To calculate a 2Â’s complement you first invert the number and then add 1. You rather mean "invert" than "calculate".And by "invert" you mean "build the 1's complement". Correct > Example 1: > 0x8000 (32768) represents -32768 What is it now? 32768 or -32768? The answer is -32768 under the given interpretation of 2's complement.. > > 0x8000 (32768) inverted = 0x7fff (32767) invert the number > 0x7fff + 0x0001 = 0x8000 (32768) add 1 > Answer is -32768 Your assumption that 0x8000 might represent 32768 is incorrect under the given circumstances. Under the given circumstances it represents -32768. Your assumption that 0x8000 inverted ends up as -32768 is incorrect, as under the given circumstances 0x8000 already represents -32768, thus, under the given circumstances, its invertion cannot represent the very number, otherwise it would not be an invertion.. > If a 1 was not added then you would have numbers from -32767 to 32767 but also have 0 (0x0000) and -0 (0xffff) and of course -0 does not exist. That's what we call a 1's complement, which does not apply here. It stands, that a number of -32768 under 2's complement cannot be inverted. Bye Achim |
| Antwort schreiben |