Arithmetic Operations On Binary Numbers: Two's Complement Addition
Arithmetic Operations On Binary Numbers: Two's Complement Addition
Arithmetic Operations On Binary Numbers: Two's Complement Addition
The nice feature with Two's Complement is that addition and subtraction of
Two's complement numbers works without having to separate the sign bits
(the sign of the operands and results is effectively built-into the
addition/subtraction calculation).
−8 ≤ x[4] ≤ +7
1. Add −8 to +3
2. (+3) 0000 0011
3. +(−8) 1111 1000
4. -----------------
5. (−5) 1111 1011
6. Add −5 to −2
7. (−2) 1111 1110
8. +(−5) 1111 1011
9. -----------------
10. (−7) 1 1111 1001 : discard carry-out
Overflow occurs if
(+A) + (+B) = −C
(−A) + (−B) = +C
A couple of definitions:
Overflow occurs if
(+A) − (−B) = −C
(−A) − (+B) = +C
Subtract −6 from +7
(+7) 0111 0111
−(−6) 1010 -> Negate -> +0110
---------- -----
13 1101 = −8 + 5 = −3 : Overflow
Addition
Subtraction
Overflow
Occurs when adding two positive numbers produces a negative
result, or when adding two negative numbers produces a positive
result. Adding operands of unlike signs never produces an overflow
Notice that discarding the carry out of the most significant bit during
Two's Complement addition is a normal occurrence, and does not by
itself indicate overflow
As an example of overflow, consider adding (80 + 80 = 160)10, which
produces a result of −9610 in 8-bit two's complement:
01010000 = 80
+ 01010000 = 80
--------------
10100000 = −96 (not 160 because the sign bit is 1.)
(largest +ve number in 8 bits is 127)
INTEGERS
Consider an n-bit vector
B = bn−1 . . . b1b0
We need to represent both positive and negative numbers. Three systems are used for
representing such numbers:
• Sign-and-magnitude
• 1’s-complement
• 2’s-complement
In all three systems, the leftmost bit is 0 for positive numbers and 1 for negative numbers.
B Values represented
01 1 1 +7 +7 +7
01 1 0 +6 +6 +6
01 0 1 +5 +5 +5
01 0 0 +4 +4 +4
00 1 1 +3 +3 +3
00 1 0 +2 +2 +2
00 0 1 +1 +1 +1
00 0 0 +0 +0 +0
10 0 0 –0 –7 –8
10 0 1 –1 –6 –7
10 1 0 –2 –5 –6
10 1 1 –3 –4 –5
11 0 0 –4 –3 –4
11 0 1 –5 –2 –3
11 1 0 –6 –1 –2
11 1 1 –7 –0 –1
Sign = 0
Mantissa = 1 1 1 0 1 1 0 0 1 1 0
Exponent =5
In floating point numbers, the bias value is added to the true exponent.
This solves the problem of representation of negative exponent.