This presentation describes the implementation of integer addition and subtraction. Before discussing the implementation it is first necessary to understand the 2's complement representation of signed integers. This representation is used by all modern computers. At least a part of the reason is the fact that addition and subtraction work the same way for 2's complement signed numbers as for unsigned binary numbers.

The last topic to be considered is errors. Any implementation of addition and subtraction has the possibility of errors due to results too large to represent in a limited number of bits. The error indications are different for unsigned and signed numbers.

Signed and unsigned addition and subtraction can be implemented with relatively simple circuitry. This circuitry is slow due to ripple carry.

A full adder (labeled FA in the diagram below) is a logic circuit for performing one column of an addition. It has three inputs, two (X and Y below) for summand bits and one (Ci below) for a carry from the column to the right. Its outputs are a sum (S below) and carry (Co below) for the column to the left. This diagram shows 4 full adders connected to compute a 4-bit sum.

#### Example 1

Consider the following addition of 8-bit integers.

```  1 1         1 1
1 1 0 0 0 0 0 1
1 1 0 0 0 0 1 1
1 0 0 0 0 1 0 0
```

If the bits represent unsigned numbers then the result is obviously in error — the sum is smaller than either of the summands. This error is indicated by the carry out from the high-order bit position (the leftmost blue 1).

On the other hand, if the bits represent signed numbers then the result is correct. You can only have an error if you add two numbers with the same sign and get a result with the opposite sign.

#### Example 2

Consider the following addition of 8-bit integers.

```    1         1 1
0 1 0 0 0 0 0 1
0 1 0 0 0 0 1 1
1 0 0 0 0 1 0 0
```

If the bits represent unsigned numbers then the result is correct. You only have an error if there is a carry out from the high-order bit position.

On the other hand, if the bits represent signed numbers then the result is obviously in error. Two numbers with the same sign are added and the result has the opposite sign.