Hardware Reference
In-Depth Information
Example B.13
Subtract 13 from 97 using two's complement arithmetic.
Solution: The 8-bit binary representations of 13 and 97 are 00001101 2 and 01100001 2 , respec-
tively. The two's complement of 13 is 11110011 2 . The value of 97 - 13 can be computed as
shown in Figure B.7.
0
1
0
1
1
1
1
1
0
0
1
1
0
0
0
0
0
1
0
1
0
1
1
0
+
1
= 84 10
Throw away
carry
Figure B.7 Subtraction by adding two's
complement of subtrahend
Example B.14
Subtract 98 from 65 using two's complement arithmetic.
Solution: The 8-bit binary representations of 98 and 65 are 01100010 2 and 01000001 2 , respectively.
The two's complement of 98 is 10011110 2 . The value of 65 - 98 is computed in Figure B.8.
0
1
1
1
0
1
0
0
0
0
1
1
0
1
1
0
1
1
0
1
1
1
0
1
+
= -33 10
Figure B.8 Subtraction by
adding two's complement of
subtrahend
The binary number 11011111 2 is the two's complement of 00100001 2 (33). Therefore, the
resultant difference is 233 and is correct.
B.13 Overflow
Overflow can occur with either addition or subtraction in two's complement representation.
During addition, overflow occurs when the sign of the sum of two numbers with like signs dif-
fers from the sign of two numbers. Overflow never occurs when adding two numbers with unlike
signs. In subtraction, overflow can occur when subtracting two numbers with unlike signs. If
Negative 2 positive 5 positive
or Positive 2 negative 5 negative
then overflow has occurred.
Overflow never occurs when subtracting two numbers with like signs.
Search WWH ::




Custom Search