Since it is well known that computers can only perform the mathematical operation
known as addition
, the implementation of subtract would require negative
To store negative
numbers in computers
, the early engineers
devised the mathematical
method known as the two's complement. The two's complement arithmetic
relies on the concepts of overflow
, which means that our operation would cause bits to be created that could not be stored. Thankfully, this is desired.
To take the two's complement, simply take the one's complement and add one. This seems overly simple, but its quite amazing. The binary representation of 13 is 00001101, so to find -13, we need take the one's complement to achieve 11110010, and then add one, 11110011.
Note: Yes, 11110011 is also 243, but engineers decided that when dealing with integer representation, half of the numbers are positive, and half negative, thus the greatest positive number that can be stored in 8 bits is 01111111, or 127. 10000000 = -128.
Now, to show the genius of the two's complement, we'll observe 13 + (-13).
+ 1111 0011
1 0000 0000
Since we cannot store a ninth digit in an eight bit
representation, we get our desired result of zero.