Circuit 3D

Half and full adder

A half adder adds two bits, giving a sum bit and a carry bit; a full adder adds three, two bits and a carry in from the column before, so full adders can be chained to add numbers of any length. A full adder’s sum is the XOR of all three inputs, so 1 + 1 + 1 gives sum 1, carry 1.

S = A ⊕ B ⊕ Cin

where ⊕ is XOR; its carry out is Cout = AB + Cin(A ⊕ B).

A half adder is just S = A ⊕ B and C = AB: one XOR gate and one AND gate.

What is a half adder?

A half adder is a logic circuit that adds two single bits, A and B, and outputs a sum bit and a carry bit, using one XOR gate and one AND gate.

Its sum is 1 when exactly one input is 1, and its carry is 1 only when both are, since 1 + 1 = 10 in binary. It is called half because it can’t accept a carry from another column. Figure 1 switches between it and the full adder.

half adder half adder A 1 B 1 Cin 1 Sum 1 Cout 1

Full adder: 1 + 1 + 1 = 3, which is 11 in binary. The first half adder adds A and B, the second adds the carry in, and the OR passes on a carry from either.

Figure 1. A half adder of an XOR and an AND gate, or a full adder of two half adders and an OR gate, with each wire’s bit.

What is a full adder?

A full adder adds three bits, A, B and a carry in, and outputs a sum bit and a carry out, so it can handle one column of a longer sum.

The largest it can add is 1 + 1 + 1 = 3, which is 11 in binary: sum 1, carry 1. Its truth table has eight rows, one for each combination of the three inputs.

How do you build a full adder from logic gates?

To build a full adder from logic gates, use two half adders and an OR gate: the first adds A and B, the second adds the carry in to that sum, and the OR combines their carries.

That is two XOR, two AND and one OR gate, or nine NAND gates, since NAND alone can make any logic gate. Its equations come straight from Boolean algebra: the carry is 1 whenever at least two inputs are.

How do you add multi-bit binary numbers?

To add multi-bit binary numbers, chain one full adder per bit, each passing its carry out to the next column’s carry in: a ripple-carry adder, so 8 bits take 8 full adders.

The lowest bit’s carry in is 0, and the last carry out becomes an extra bit when the answer outgrows the width, as Figure 2 shows. The 74HC283 is a 4-bit adder on one chip. Because each carry waits for the one before, long ripple adders are slow; processors use carry-lookahead adders that work out the carries in parallel.

A B 0 FA 0 0 1 FA 1 1 0 FA 1 0 1 FA 0 1 1 bit 0 on the right

6 + 5 = 11: 0110 + 0101 = 1011. Each full adder passes its carry left to the next.

Figure 2. Four full adders in a row add two 4-bit numbers, with A’s bit and B’s bit over each adder and the carry rippling from right to left.

How does binary addition work?

Binary addition works exactly like decimal column addition, but each column holds only 0 or 1, so 1 + 1 writes 0 and carries 1 to the next column.

The four rules are 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10, and with a carry, 1 + 1 + 1 = 11. A full adder is those rules in gates, one column at a time.

How does an adder subtract?

An adder subtracts by flipping every bit of the number being subtracted and setting the carry in to 1, which adds its negative in two’s complement, so A − B comes out of the same adder.

On four bits, a carry out of 1 means the answer is zero or positive; no carry means it is negative, stored as 16 more than its value, as Figure 3 shows. This is why a processor’s arithmetic logic unit needs only adders, plus flip-flops to hold the numbers.

A 91001 NOT B (5)1010 carry in1 sum10100 = 4

9 − 5: adding NOT B and a carry in of 1 adds 16 − 5, so the sum is 9 − 5 + 16; the carry out of 1 is that 16, and the four bits left, 0100, are 4.

Figure 3. A 4-bit adder subtracting: B’s bits are flipped and the carry in set to 1, which adds minus B in two’s complement.

How big and how fast is an adder?

To size an adder, count one full adder per bit and five gates per full adder, so 8 bits take 40 gates; for speed, the worst carry crosses two gates in every adder.

Example 1: building an adder

How many full adders and logic gates does a ripple-carry adder for two 8-bit numbers need?

Given
a ripple-carry adder for two 8-bit numbers
Find
how many full adders and gates it takes
Solution
One full adder per bit: 8Each has 2 XORs, 2 ANDs and an OR: 8 × 5 = 40 gates
Answer
8 full adders, 40 gates

Example 2: how long the carry takes

Each gate takes about 10 ns to switch. How long can the carry take to ripple through a 8-bit adder?

Given
a 8-bit ripple-carry adder built from gates that take about 10 ns each
Find
how long the slowest carry takes to ripple through
Solution
Each full adder’s carry passes an AND then an OR: 2 × 10 ns = 20 ns8 adders × 20 ns = 160 ns
Answer
about 160 ns

Summary

Key equations

  • S = A ⊕ B, C = AB half adder
  • S = A ⊕ B ⊕ Cin full adder sum
  • Cout = AB + Cin(A ⊕ B) full adder carry
  • A − B = A + NOT B + 1 two’s complement

Key terms

Carry
The bit passed to the next column.
Ripple carry
Carries passed along a chain.
Two’s complement
Negatives as flipped bits plus 1.
ALU
A processor’s arithmetic unit.

Practice problems

  1. A half adder adds 1 + 1. What are its outputs?

  2. A full adder adds 1 + 1 + 1. What are its outputs?

  3. Which gate gives a half adder’s sum?

  4. How many full adders add two 16-bit numbers in a ripple-carry adder?

  5. What is 0111 + 0011 in binary?

FAQ

What is the difference between a half adder and a full adder?

A half adder adds two bits; a full adder adds three, including a carry in from the previous column, so full adders chain together.

Why is it called a half adder?

Because it does half the job of a full adder: it can’t take a carry in, so it only suits the lowest column.

How many gates are in a full adder?

Five in the usual design: two XOR, two AND and one OR. Built from NAND gates alone, it takes nine.

What is a ripple-carry adder?

A chain of full adders, one per bit, each passing its carry to the next. Simple, but each carry waits for the one before.

What is a carry-lookahead adder?

A faster adder that works out every column’s carry at once from the inputs, instead of waiting for carries to ripple along.

What chip is a 4-bit adder?

The 74HC283, which adds two 4-bit numbers and a carry in, with a carry out for chaining.

Can an adder subtract?

Yes: flip the second number’s bits and set the carry in to 1, which adds its two’s complement negative.

What is binary?

A way of writing numbers with only two digits, 0 and 1, where each place is worth twice the one to its right, so 101 is 4 + 0 + 1 = 5.