
|
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). > Hello Achim, I think you are making a thinking error ;). To calculate a 2Â’s complement you first invert the number and then add 1. Example 1: 0x8000 (32768) represents -32768 0x8000 (32768) inverted = 0x7fff (32767) invert the number 0x7fff + 0x0001 = 0x8000 (32768) add 1 Answer is -32768 Example 2: 0xffff (65535) represents -1 0xffff (65535) inverted = 0x0000 (0) invert the number 0x0000 +0x0001 = 0x0001 (1) add 1 Answer is -1 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. Greetings, H.J.W. |
| Antwort schreiben |