What’s difference between 1’s Complement and 2’s Complement?

1’s complement of a binary number is another binary number obtained by toggling all bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0.
Let numbers be stored using 4 bits
1’s complement of 7 (0111) is 8 (1000)
1’s complement of 12 (1100) is 3 (0011)

2’s complement of a binary number is 1 added to the 1’s complement of the binary number.
Let numbers be stored using 4 bits
2’s complement of 7 (0111) is 9 (1001)
2’s complement of 12 (1100) is 4 (0100)

let’s make it simple:
0111’s 1’s complement is 1000, which flips every bit
0111’s 2’s complement is 1001, which (flips every bit + 1)

The main difference between 1′ s complement and 2′ s complement is that 1′ s complement has two representations of 0 (zero) – 00000000, which is positive zero (+0) and 11111111, which is negative zero (-0); whereas in 2′ s complement, there is only one representation for zero – 00000000 (+0) because if we add 1 to 11111111 (-1), we get 00000000 (+0) which is the same as positive zero. This is the reason why 2′ s complement is generally used.

Another difference is that while adding numbers using 1′ s complement, we first do binary addition, then add in an end-around carry value. But, 2′ s complement has only one value for zero, and doesn’t require carry values.

posted @ 2021-01-09 06:34  EvanMeetTheWorld  阅读(72)  评论(0)    收藏  举报