Signed integers (cont)
Signed magnitude: Easy to form -X from X ... XOR in high-order bit
A problem (using 8-bit int s) ...
- what do these numbers represent?
00000000 , 10000000
Two zeroes ... one positive, one negative
Another problem: x + -x ≠ 0 (mostly) with simple addition
00000011 3 00101010 42 01111111 127
+ 10000011 -3 + 10101010 -42 + 11111111 -127
-------- -------- --------
10000110 !0 11010100 !0 01111110 !0
|
To fix requires extra hardware in ALU (Arithmetic Logic Unit) in the CPU
|