At this moment, you understand how to represent integer numbers in the binary format. In practice, we also use negative numbers to represent some facts about the real world such as a negative temperature. In this topic, you will learn how to represent such numbers in the binary format.
One's complement notation
There are several notations to represent integer negative numbers in the binary format. Let's consider the notation known as one's complement.
In this notation, a non-negative number is represented by its ordinary binary representation. The one's complement for a negative number is obtained by inverting all the digits in a binary number (0 → 1, 1 → 0). It's like a mirror image of a binary number.
Suppose we would like to get the one's complement of the decimal number -3.
The unsigned binary representation of this number is 0011. So, the one's complement form is 1100.
An N-bit one's complement of a number is this number inverted in such a way that it contains strictly N digits. For instance, 1-bit one's complement of 1 is 0, 2-bit is 10, 8-bit is 11111110, and so on.
Computing one's complement of a value is the same as subtracting this value from 0.
Examples
One's complement notation is an important concept used for representing negative binary numbers in computer memory. Any negative binary number can be represented as one's complement of its corresponding positive number.
Here is a table containing examples of some numbers in the one's complement form using only 4 bits.
| Decimal | Unsigned binary | One's complement |
| -3 | 0011 | 1100 |
| -2 | 0010 | 1101 |
| -1 | 0001 | 1110 |
| 0 | 0000 | 0000 (or 1111) |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0010 |
| 3 | 0011 | 0011 |
It is not necessary to memorize this table: just make sure that you understand why this is true. Pay attention to different ways of representing zero.
Binary arithmetics: negatives
We talked about binary arithmetics before, but negative binary arithmetics is a bit trickier.
First, let's see how to subtract larger numbers from smaller numbers. Let's try subtracting 111100 from 100010 (60 from 34 in decimal):
Just like with subtracting positives, if we need to subtract 1 from 0, we borrow from the next left digit. When there's nothing left to borrow from, the borrow is wrapped around. This means that we subtract the borrowed 1 from the rightmost end of our result. Essentially, we have carried our borrow all the way to the right and then moved it to another end, where we finally subtracted.
The result is 1100101. This number inverted (remember that the answer is negative) is 11010, which is 26 in binary, so our answer is -26. Correct!
So, negative binary addition and subtraction work the same as with positives, except for three things:
- When our expected answer is negative, it's written in one's complement notation.
- If we borrow from a smaller number, the borrow is wrapped around to the rightmost end.
- If we carry while adding a negative number, the carry is also wrapped around to the rightmost end.
Dealing with zeroes
Because zero is neither positive nor negative, in one's complement notation it can be represented as both 00000000 and 11111111. The first is called positive zero, the second is negative zero. Both values behave as zero when added or subtracted, so signed zero shouldn't be a problem when computing manually.
Try it yourself:
We add negative zero since our zero is negative; the carried 1 (marked in bold) is wrapped around to the rightmost end.
We subtracted negative zero.
Usage
Although modern computers almost never use one's complement notation to represent negative integers (preferring another, more complex notation called two's complement), most of the early computers used it.