Two’s complement is a technique for representing signed numbers in binary. The method representing a negative number is a simple two-step process:
The powerful thing about two’s complement representation is that we can perform arithmetic with the numbers as they are, and the answer we get will be the correct representation in two’s complement. But why does this simple technique work and result in such a mathematically consistent representation?
It is simply the result of subtracting the absolute value of the number from
Let us see how this is true.
Suppose we want to come up with a representation for - in binary. We know - is less than , . We can try and compute this using the borrow method if we infinitely keep borrowing from the on the left.
Although our answer will have a never-ending string of 's at its left, we can simply truncate after bits because that is all our computer will store – so this is our negative representation.
Now let’s follow the two’s complement method to find -.
This is exactly the same as subtracting from using the borrow method. Now you know what two’s complement does.
Free Resources