In computers, all arithmetic is done in terms of logic. A couple of logic gates make up the half adder. A couple of half adders make a full adder, and a series of full adders make up the mechanism that adds two binary strings. Half adders take two inputs and produce a sum and a carry. Full adders take three inputs and produce a sum and a carry. All computer arithmetic is based on addition, and all addition is based on logical operations. To explain full adders, start with logic gates and work up.

- Skill level:
- Moderate

### Other People Are Reading

## Instructions

- 1
Use logic gates to build a half adder. Logic gates have two inputs and produce an output determined by the type of the gate. An AND gate has a 0 output unless both inputs are 1. An XOR gate has an output of 0 when both inputs are the same, and an output of 1 when the inputs are different. The input to a half adder goes to both an AND gate and an XOR gate. The output of the XOR gate is the "sum" output of the half adder, and the output of the AND gate is the "carry" output of the half adder.

- 2
Connect two half adders together to make a full adder. Two of the inputs go to the first half adder, and the "sum" output of the first half adder and the third input goes to the inputs of the second half adder. The "sum" output of the second half adder becomes the "sum" output of the full adder. The "carry" outputs from both half adders go to an OR gate. An OR gate has an output of 1 unless both inputs are 0. The output of the OR gate becomes the "carry" output of the full adder.

- 3
Make a row of full adders as long as the length of the binary strings you want to add. Make the carry from each full adder go to the third input of the next full adder. The first full adder will only need to use two of its inputs because there is no previous stage, so no carry from a previous stage, and the carry from the last full adder indicates an overflow -- a number too big for the row of full adders to handle.

#### Tips and warnings

- Subtraction is accomplished by making the second number negative, then adding. Multiplication is done by a series of shifts and additions. Division is accomplished by a series of subtractions and shifts. All arithmetic is accomplished by the one row of full adders.
- A long row of binary digits will almost always have a carry, and that carry will have another carry and so on. This process is called "ripple." When designing adders, allow enough time for both the additions and the maximum amount of ripple. The chance for carry when adding two bits is one in four. The chance for a carry when adding three bits is one in two.