1,2 Complement, Signed Lecture-06
1,2 Complement, Signed Lecture-06
(BCAC-102)
Lecture#06
1’s and 2’s Complements
Lecture Outline
Minued - 110101
+1
010000
Solution:
Minued - 101011
Solution:
1’s complement of subtrahend 0110.100 is 1001.011 Hence
Minued - 1 0 1 1. 0 0 1
1’s complement of subtrahend - 1 0 0 1. 0 1 1 (+)
Carry over - 1 0 1 0 0. 1 0 0
(+) 1
0 1 0 0. 1 0 1
Subtraction of a smaller number from a larger one by the 2’s complement method involves following steps:
Subtract (1010) from 1111 using 2’s complement method. Subtract by direct method also.
1111 (+)
2’s complement of smaller number 0110
carry….. 1 0101
To get an answer in true form, take the 2’s complement and change the sign.
Subtract (1010)2 from (1000)2 using 2’s complement method. Subtract by direct method also.
1000 (+)
0110
No carry 1110
No carry is obtained. Thus, the difference is negative and the true answer is the 2’s complement of
(1110)2 i.e. (0010)2
Binary numbers are represented with a separate sign bit along with the magnitude, as shown below. For example, in
an 8-bit binary number, the MSB is the sign bit and the remaining 7 bits correspond to magnitude. The magnitude
part contains true binary equivalent of the number for positive numbers, while 2’s complement form of the number
for negative numbers. For example, +13, 0, -46 are represented as follows:
Sign Magnitude
+13
0 000 1101
0
0 000 0000
-46
1 010 1110
It is important to note that the number zero is assigned with the sign bit ‘0’. Therefore, the range of numbers that
can be represented using 8-bit binary number is -128 to +127. In general, the range of numbers that can be
represented by an n-bit number is ( ) to (+2n-1 -1).
Add the following numbers using 2’s complement system:
a) +29 and +19 b) +39 and -22 c) -47 and +29 d) -32 and -44
Solution:
(a) +29 0 001 1101 (augend)
+19 0 001 0011 (addend)
Sign bit
The sign bits of both augend and addend are zero and sign bit of the sum is 0, indicating that
when the sum is positive they have the same number of bits.
Solution: (b) +39 and -22
Consider the addition of +39 and -22. Remember that -22 will be in its 2’s complement form.
Therefore, +22 [00010110] must be converted to -22 [11101010]
In this case, the sign bit of addend is 1. Sign bits also participate in the process of addition; in fact, a carry
is generated in the last position of addition. This carry is always omitted. Therefore, the final sum is
0001 0001, which is equivalent to +17.
a) Subtract 19 from 28
To subtract -21 from +39, the computer will send the -21 to a 2’s complement circuit to produce
+21 0001 0101
Assignments:
Consider the addition of +120 and +65. As the decimal sum of +120 and +65 is +185, an overflow occurs
into the MSD position. This overflow forces the sign bit of the answer to change.
As the sign bit is one, i.e. negative, the answer is not correct.
Similarly in the case of two negative numbers overflow occurs.
An overflow is a software problem and not a hardware problem. In digital computers, an overflow
occurs when an operation results in a quantity beyond the capacity of the storage register. Therefore a
programmer must check the overflow after each addition or subtraction by looking for a change in the
sign bit. Logic circuitry is used in each case to detect overflow.
The 1’s complement can be easily obtained using an inverter. The 2’s complement has to
be arrived at by first obtaining the 1’s complement and then adding one(1) to it.
The advantage in the 2’s complement system is that only one arithmetic operation is
required ; the 1’s complement requires two operations.
While the 1’s complement is often used in logical manipulations for inversion operation,
the 2’s complement is used only for arithmetic applications.