Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 Re: Zahlenbereich Darstellung Kategorie: Verschiedenes (von H.J.W. - 26.10.2006 19:14)
 Als Antwort auf Re: Zahlenbereich Darstellung von Achim - 26.10.2006 16:27
> 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

Bisherige Antworten:

Re: Zahlenbereich Darstellung (von Achim - 27.10.2006 2:34)
    Re: Zahlenbereich Darstellung (von Dietmar - 27.10.2006 15:54)
    Re: Zahlenbereich Darstellung (von H.J.W. - 27.10.2006 11:55)