Section 6.3
Signed binary numbers (integers)

The methods shown above give positive binary numbers for positive decimal numbers. Actually, they are numerals, but we will not quibble over philosophical distinctions, not when there's a computer to build!! The next problem to tackle is how to encode negative numbers.

There are three main methods of doing this, the first one being the most obvious and intuitive, called sign-magnitude form. Merely add an extra bit to the binary number to encode the sign. The most obvious encoding is to use 0 for + and 1 for -, probably because if the minus is rotated 90o, it looks like a 1. The one tricky point is that the maximum number of bits must be set and then the number must be padded out with 0s so that the minus sign is always in the same bit position. For instance, an 8-bit number must add a 9th bit for the sign, usually at the front. Thus, +1 becomes 000000001 and -1 is 100000001. Note the extra padding zeroes. If they weren't there, the representation for -1 would be 11, which looks like 3. In fact, there would be no way to tell between 3 and -1.

Here are some more positive and negative numbers using sign-magnitude form, using several different bit lengths:

number     4 bits     8 bits     12 bits
------     ------     ------     -------
0          0000       00000000   000000000000
1          0001       00000001   000000000001
-1         1001       10000001   100000000001
-15        can't do   10001111   100000001111
7          0111       00000111   000000000111
-7         1111       10000111   100000000111
8          can't do   00001000   000000001000
-8         can't do   10001000   100000001000
576        can't do   can't do   001001000000
-576       can't do   can't do   101001000000

Some values can't fit within the number of bits that are set for the numbers. For example, 16 can't be expressed in fewer than 5 bits. If one of the bits assigned to be the sign, the size of the numbers that can be encoded is restricted even further. Thus, a 4-bit sign magnitude form, as shown in the second column above, can only accommodate 3 actual bits of binary number, since one of the 4 is the sign. 1112 is 7, so 4-bit sign-magnitude form can only accommodate -7 to +7. 8-bit sign magnitude can only accommodate -127 to +127, since 01111111 is 127. What is the range of numbers if we are using 12-bits?

One strange thing about sign-magnitude form is that there are two values for 0. Using 4 bits, 0000 and 1000 both exist, although the second is -0. In real life, there is no -0, simply 0. Thus, one bit pattern is either meaningless or means the same as another bit pattern. If a computer would ever come up with 1000, or -0, as a result of a calculation, such as subtraction, it should convert it to 0000 just to be consistent and to ensure that it doesn't inadvertently think that 0 does not equal -0.

Another method of encoding negative integers is called 2's complement. This notation is more widely used than sign-magnitude because it is easier to implement subtraction. However, 2's complement is more difficult for humans to understand.

First, let's look at a simpler system called 1's complement. In 1's complement notation, negative numbers are formed by inverting all the bits of the positive form. Again, the size of the numbers must be fixed once and for all. Here are the same values as given above, only using 1's complement.

number     4 bits     8 bits     12 bits
------     ------     ------     -------
0          0000       00000000   000000000000
1          0001       00000001   000000000001
-1         1110       11111110   111111111110
-15        can't do   11110000   111111110000
7          0111       00000111   000000000111
-7         1000       11111000   111111111000
8          can't do   00001000   000000001000
-8         can't do   11110111   111111110111
576        can't do   can't do   001001000000
-576       can't do   can't do   110110111111

However, -0 still exists in 1's complement. It is 1111 in 4 bits, 11111111 in 8 bits, and all ones for any size bit pattern.

The nice thing about 1's complement is that a special subtraction circuit isn't needed. Instead, just add the negative of a number. We will not go through this process here because 1's complement is merely a stepping stone for 2's complement.

Virtually all modern computers use 2's complement to represent signed binary numbers internally. In the next section we will learn how to convert between 2's complement and decimal.