Signed integers (cont)
Twos complement: to form -X from X ... NEG all bits, then add 1
Now have only one representation for zero (00000000 )
-
-0 = ~00000000+1 = 11111111+1 = 00000000
Only one zero value. Also, -(-x) = x
Even better, x + -x = 0 in all cases with simple addition
00000011 3 00101010 42 01111111
+ 11111101 -3 + 11010110 -42 + 10000001
-------- -------- --------
00000000 0 00000000 0 00000000 0
|
Always produces an "overflow" bit, but can ignore this
|