Share on facebook
Share on linkedin
Share on twitter
Share on pinterest
Share on google


Well so far we have just seen positive integers mainly. Now let us speak about negative integers as well. When speaking about this, we can figure out a simple solution. Like in Math's, instead of adding a + or - at the beginning of the number we add a zero or a one. But there is kind of a problem here.

When adding a 0 or a 1 in the first bit, we tend to come to a problem. That is, that we have two values for zero, as such this causes first: a bit of an inefficiency that is not really that bad. Because it is just one bit lost, but the real problem comes when were are adding or subtracting. Because we have the value of zero twice. In the 0's complement case we have 0000 and 1000 so if you add 1 to 1000 you get 0000 which would mean : 0 + 1 = 0.

To overcome this problem, we do something called a first and second complement of any given positive integer. A one's complement is when we invert all the values of the numbers so:

0000 would then be 1111 and 10110 would be 01001. Very easy and simple. But we still have the same problem when we do a one's complement so we do something called a second complement. This is when we add one to the inverted value. So for example we would have:

Number: 10011

First Complement: 01100

Second's Complement: 01101

Positive numbers are generally stored as is and negative numbers are stored as a second complement.