Hardware Reference
In-Depth Information
Example B.15
Does overflow occur in the following 8-bit operations?
a. 01111111 2 2 00000111 2
b. 01100101 2 1 01100000 2
c. 10010001 2 2 01110000 2
Solution: These subtraction operations are illustrated in Figure B.9 to B.11.
a. Negation of 00000111 2 is 11111001 2 . 01111111 2 2 00000111 2 is performed as follows:
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
0
0
1
1
0
+
1
Carry out to be discarded
Figure B.9 Example of addition that causes
no overflow
The difference is 01111000 2 5 120 10 . There is no overflow.
b. The sum of these two numbers is as follows:
0
0
1
1
1
1
1
1
0
0
0
0
0
0
0
1
0
1
0
0
0
1
0
1
+
The sign has changed from positive to negative
Figure B.10 Example of addition that
causes overflow
Overflow has occurred.
c . The two's complement of 01110000 2 is 10010000 2 . 10010001 2 2 01110000 2 is performed as
follows:
1
1
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0
0
0
1
0
1
+
Carry out to be discarded
1
.
The sign has changed from negative to positive
Figure B.11 Another example of addition that
causes overflow
Overflow has occurred.
An important benefit of using two's complement arithmetic is that the same computer
hardware can perform signed and unsigned (all numbers are nonnegative) addition and subtrac-
tion without modification. It is up to the user to interpret the number to be negative.
Search WWH ::




Custom Search