TOPIC 4.1.1
Storing Integers


Consider the representation of unsigned integers. A typical representation is a block of 32 bits. Fast circuitry is provided in most computers to easily add, multiply and divide unsigned integers. The interpretation of unsigned integers from 0 to 15 are illustrated below using 4 bits.

0000     0*8 + 0*4 + 0*2 + 0*2 = 0
0001     0*8 + 0*4 + 0*2 + 1*2 = 1
0010     0*8 + 0*4 + 1*2 + 0*2 = 2
0011     0*8 + 0*4 + 1*2 + 1*2 = 3
0100     0*8 + 1*4 + 0*2 + 0*2 = 4
0101     0*8 + 1*4 + 0*2 + 1*2 = 5
0110     0*8 + 1*4 + 1*2 + 0*2 = 6
0111     0*8 + 1*4 + 1*2 + 1*2 = 7
1000     1*8 + 0*4 + 0*2 + 0*1 = 8
1001     1*8 + 0*4 + 0*2 + 1*1 = 9
1010     1*8 + 0*4 + 1*2 + 0*1 = 10
1011     1*8 + 0*4 + 1*2 + 1*1 = 11
1100     1*8 + 1*4 + 0*2 + 0*1 = 12
1101     1*8 + 1*4 + 0*2 + 1*1 = 13
1110     1*8 + 1*4 + 1*2 + 0*1 = 14
1111     1*8 + 1*4 + 1*2 + 1*1 = 15

The electronic circuitry is designed to obey the rules of binary addition. If we add 0001 and 1110 in the circuit, the answer will be 1111. The circuit knows nothing about negative integers, nor subtraction. Then, how can we use this computer to perform arithmetic on negative values?

One answer is to impose a different interpretation of unsigned integers in software. An example using 4 bits is shown below.

0000     = 0
0001     = 1
0010     = 2
0011     = 3
0100     = 4
0101     = 5
0110     = 6
0111     = 7
1000     = -8
1001     = -7
1010     = -6
1011     = -5
1100     = -4
1101     = -3
1110     = -2
1111     = -1

This is just a new interpretation of the same 4-bit unsigned integers used earlier. Software that use signed integers will need to impose this new interpretation. However, no changes to the electronic circuitry is needed. The existing electronic circuitry used for adding unsigned integers happens to preserve the new interpretation. For example:

  0010 (+2)     0011 (+3)     1111 (-1)     1111  (-1)
+ 1111 (-1)   + 1100 (-4)   + 1110 (-2)   * 0010  (+2)
-----------   -----------   -----------   ------------
  0001 (+1)     1111 (-1)     1101 (-3)     1110  (-2)

As far as the computer is concerned, we are still just adding together unsigned integers. This trick is called "2's complement" arithemetic, and is used widely. By changing the interpretation we place on unsigned integers, we are able to use the circuitry for addition to perform subtractions as well. The only extra circuitry required is a circuit for bit-complementing.