Adders are logic circuits that add binary digits. The arithmetic logic unit of a processor uses them to add whole binary numbers.
Half Adder
| A | B | S (sum) | C (carry) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
• S = A ⊻ B (A XOR B)
• C = A ∧ B (A AND B)
Circuit: A and B are both connected to an XOR gate, whose output is S, and both connected to an AND gate, whose output is C. There are no other gates.
A half adder has no input for a carry, so it can only add the right-hand column of two numbers. Every other column may have a carry coming in from the column before it.
Full Adder
| A | B | Cin | S | Cout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
• S = A ⊻ B ⊻ Cin
• Cout = (A ∧ B) ∨ (Cin ∧ (A ⊻ B))
• The first half adder adds A and B
• The second half adder adds the sum from the first to Cin. Its sum output is S
• The carry outputs of the two half adders go into an OR gate. The output of the OR gate is Cout
So a full adder is two half adders joined by an OR gate.
Adding Multi-Bit Numbers
Full adders are chained together to add numbers with more than one bit. One full adder is used for each column, and the carry out of each adder is connected to the carry in of the next one to its left. Adding two 4-bit numbers needs four full adders. The carry out of the last adder is the fifth bit of the answer, or shows that the result has overflowed.
• A half adder is one XOR gate and one AND gate, with no extra gates
• "Two half adders joined with an OR gate" is the description of a full adder
• For adding n-bit numbers, say that n full adders are used and that the carry out of one is joined to the carry in of the next