Hardware Reference
In-Depth Information
B.11 Two's Complement Numbers
In a computer, the number of bits that can be used to represent a number is fixed. As a
result, computers always manipulate numbers that are fixed in length.
Another restriction on number representation in a computer is that both positive and negative
numbers must be represented. However, a computer does not include the plus and minus signs in
a number. Instead, all modern computers use the two's complement number system to represent
positive and negative numbers. In the two's complement system, all numbers that have a most
significant bit (MSB) set to 0 are positive , and all numbers with an MSB set to 1 are negative . Posi-
tive two's complement numbers are identical to binary numbers, except that the MSB must be a 0.
If N is a positive number, then its two's complement N C is given by
N C 5 2 n 2 N
(B.1)
where n is the number of bits available for representing N .
The two's complement of N is used to represent - N . Machines that use the two's comple-
ment number system can represent integers in the range
2 2 n 21 # N # 2 n 2 1 2 1
(B.2)
Example B.11
Find the range of integers that can be represented by an 8-bit two's complement number
system.
Solution: The range of integers that can be represented by the 8-bit two's complement number
system is
2 2 7 # N # 2 7 2 1 or 2 128 10 # N # 127 10
Example B.12
Represent the negative binary number 211001 2 in 8-bit two's complement format.
Solution: Use Equation B.1 and the subtraction method in Section B.11.
N C 5 2 8 2 11001 5 11100111 2
An easy way to find the two's complement of a binary number is to flip every bit from 0 to 1
or 1 to 0 and then add 1 to it.
B.12 Two's Complement Subtraction
Subtraction can be performed by adding the two's complement of the subtrahend. This al-
lows the same piece of hardware to perform addition and subtraction. All of today's computers
use this method to perform subtraction.
After the addition, throw away the carry generated from the most significant bit and the
result is the desired difference. If the most significant bit is 0, then the resultant difference is
positive. Otherwise, it is negative.
Search WWH ::




Custom Search