Adding two numbers on paper is done one column at a time, with a carry passed to the next column. A processor adds in exactly the same way, and the circuit that performs one column of the addition is called an adder.

Half Adder

A half adder adds two single bits A and B and produces two outputs, the sum S and the carry C. The sum is 1 when exactly one input is 1, and the carry is 1 only when both inputs are 1. Therefore S = A ⊕ B and C = A·B, where ⊕ is the XOR operation.

Definition: Half adder. A combinational circuit that adds two binary digits and gives a sum bit and a carry bit. It cannot accept a carry from a previous stage.

Table 2.1: Truth table of the half adder

A B Sum S Carry C
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

Full Adder

A half adder cannot be used for the second and higher columns, because those columns must also add the carry from the column on the right. A full adder adds three bits, A, B and the carry-in Cin. Its outputs are S = A ⊕ B ⊕ Cin and Cout = A·B + Cin·(A ⊕ B). Table 2.2 gives its truth table. A full adder can be built from two half adders and an OR gate.

Table 2.2: Truth table of the full adder

A B Cin Sum 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

Map of the Carry Output

The carry-out of the full adder can be simplified with a K-map.

Example 2.1: Adding two 4-bit numbers with full adders

Problem: Add 1011 and 0110 using four full adders connected in a chain.

Solution:

  1. Column 0: 1 + 0 + 0 gives sum 1, carry 0.
  2. Column 1: 1 + 1 + 0 gives sum 0, carry 1.
  3. Column 2: 0 + 1 + 1 gives sum 0, carry 1.
  4. Column 3: 1 + 0 + 1 gives sum 0, carry 1, which becomes the final carry-out.

Result: The sum is 1 0001, which is 11 + 6 = 17.

def fa(a, b, c):
    return a ^ b ^ c, (a & b) | (c & (a ^ b))
a, b, c, out = [1, 1, 0, 1], [0, 1, 1, 0], 0, []
for x, y in zip(a[::-1], b[::-1]):
    s, c = fa(x, y, c)
    out.append(s)
print(c, out[::-1])

Output

1 [0, 0, 1, 1]

Common mistakes

  • Using a half adder for a column that receives a carry-in.
  • Writing the carry of a half adder as A + B instead of A·B.
  • Forgetting the final carry-out when the sum needs one more bit.

Key takeaways

  • Half adder: S = A ⊕ B and C = A·B.
  • Full adder: S = A ⊕ B ⊕ Cin and Cout = AB + Cin(A ⊕ B).
  • A full adder can be made from two half adders and an OR gate.
  • Full adders chained together add multi-bit numbers.

Practice questions

  1. What is the carry output of a half adder for inputs 1 and 1?
  2. How many inputs does a full adder have?
  3. Write the sum equation of a full adder.

Answers to the practice questions

  1. Three: A, B and the carry-in.
  2. S = A XOR B XOR Cin.

Sources

  • Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit II