![]() |
VOOZH | about |
1's Complement and 2's Complement are two methods to represent signed (positive and negative) integers in binary form. Both methods allow computers to perform arithmetic operations with both positive and negative numbers.
The 1's complement of a binary number is obtained by flipping all the bits, i.e., converting every 0 to 1 and every 1 to 0.
Let numbers be stored using 4 bits
1’s complement of 0111 (7) is 1000
1’s complement of 1100 (12) is 0011
2's complement is another binary number representation technique used widely in modern computers. To obtain the 2's complement of a binary number, you invert all the bits (similar to 1's complement) and add 1 to the least significant bit.
In practice, computers do not compute the 2’s complement explicitly; arithmetic circuits handle negative numbers automatically using binary addition.
2's complement of a binary number is 1 added to the 1's complement of the binary number. Examples:
Let numbers be stored using 4 bits
2’s complement of 0111 (7) is 1001
2’s complement of 1100 (12) is 0100
These representations are used for signed numbers.
The main difference between 1’s complement and 2’s complement is that 1’s complement has two representations of zero:
In 2’s complement, there is only one representation of zero:
This happens because adding 1 to 11111111 results in 100000000 (for 8-bit), and the overflow bit is discarded, leaving 00000000. Therefore, 2’s complement avoids duplicate zero representation and is widely used.
Another difference is in addition:
Range of numbers:
| 1's Complement | 2's Complement |
|---|---|
| Invert all bits | Invert all bits + add 1 |
| Two zeros (+0 and -0) | One zero (0) |
| Needs end-around carry | No carry needed |
| Range: −(2n-1−1) to (2n-1−1) | Range: -(2n-1) to (2n-1-1) |
| Rarely used | Standard in modern systems |