2’s complement
Just like 1’s complement, 2’s complement is also used to represent the signed binary numbers. For finding 2’s complement of the binary number, we will first find the 1’s complement of the binary number and then add 1 to the least significant bit of it.
For example, if we want to calculate the 2’s complement of the number 1011001, then firstly, we find the 1’s complement of the number that is 0100110 and add 1 to the LSB. So, by adding 1 to the LSB, the number will be (0100110)+1=0100111. We can also create the logic circuit using OR, AND, and NOT gates. The logic circuit for finding 2’s complement of the 5-bit binary number is as follows:
Example 1: 110100
For finding 2’s complement of the given number, change all 0’s to 1 and all 1’s to 0. So the 1’s complement of the number 110100 is 001011. Now add 1 to the LSB of this number, i.e., (001011)+1=001100.
Example 2: 100110
For finding 1’s complement of the given number, change all 0’s to 1 and all 1’s to 0. So, the 1’s complement of the number 100110 is 011001. Now add one the LSB of this number, i.e., (011001)+1=011010.
2’s Complement Table
Binary Number | 1’s Complement | 2’s complement |
---|---|---|
0000 | 1111 | 0000 |
0001 | 1110 | 1111 |
0010 | 1101 | 1110 |
0011 | 1100 | 1101 |
0100 | 1011 | 1100 |
0101 | 1010 | 1011 |
0110 | 1001 | 1010 |
0111 | 1000 | 1001 |
1000 | 0111 | 1000 |
1001 | 0110 | 0111 |
1010 | 0101 | 0110 |
1011 | 0100 | 0101 |
1100 | 0011 | 0100 |
1101 | 0010 | 0011 |
1110 | 0001 | 0010 |
1111 | 0000 | 0001 |
Use of 2’s complement
2’s complement is used for representing signed numbers and performing arithmetic operations such as subtraction, addition, etc. The positive number is simply represented as a magnitude form. So there is nothing to do for representing positive numbers. But if we represent the negative number, then we have to choose either 1’s complement or 2’s complement technique. The 1’s complement is an ambiguous technique, and 2’s complement is an unambiguous technique. Let’s see an example to understand how we can calculate the 2’s complement in signed binary number representation.
Example 1: +6 and -6
The number +6 is represented as same as the binary number. For representing both numbers, take the 5-bit register.
So the +6 is represented in the 5-bit register as 0 0110.
The -6 is represented in the 5-bit register in the following way:
- +6=0 0110
- Now, find the 1’s complement of the number 0 0110, i.e. 1 1001.
- Now, add 1 to its LSB. When we add 1 to the LSB of 11001, the newly generated number comes out 11010. Here, the sign bit is one which means the number is the negative number.
Example 2: +120 and -120
The number +120 is represented as same as the binary number. For representing both numbers, take the 8-bit register.
So the +120 is represented in the 8-bit register as 0 1111000.
The -120 is represented in the 8-bit register in the following way:
- +120=0 1111000
- Now, find the 1’s complement of the number 0 1111000, i.e. 1 0000111. Here, the MSB denotes the number is the negative number.
- Now, add 1 to its LSB. When we add 1 to the LSB of 1 0000111, the newly generated number comes out 1 0001000. Here, the sign bit is one, which means the number is the negative number.