Skip to main content

Level 0: How computers work · 10 min

Half adder: adding two bits

Goal: build a circuit that adds two bits.
You need: Binary and Logic gates.

An easy start: counting apples

You have 1 apple and get 1 more. Now you have 2.

A computer only has 0 and 1. There is no digit "2". From the binary lesson, two is written as 10.

So adding two bits needs two answer boxes:

  • Sum: the right box.
  • Carry: the left box. It is the part that moves to the next position.

You already carry

When you add 7 + 5 on paper, you get 12. You write 2 and carry 1 to the left. In binary the same thing happens, only sooner.

All the cases

One bit is 0 or 1, so adding two bits has only 4 cases.

A + BCarrySumMeans
0 + 000zero
0 + 101one
1 + 001one
1 + 110two

Find the gates

Look at one column at a time.

Sum is 1 only for 0 + 1 and 1 + 0. That is when the two bits are different. Which gate does that? XOR.

Carry is 1 only for 1 + 1. That is when both bits are 1. Which gate does that? AND.

We did not invent anything new. We used two gates you already know.

The circuit

Send A and B into both gates at the same time. XOR gives the sum. AND gives the carry. This circuit is called a half adder.

Try it

Before you flip a switch, say the sum and the carry. Then check.

0
0

Sum 0 Carry 0 Binary 00 = 0

ABSum (XOR)Carry (AND)
0000
0110
1010
1101

Why "half"?

Think about adding bigger numbers, such as 11 + 11 (that is 3 + 3).

The right column is 1 + 1. A half adder can do it: sum 0, carry 1.

The next column has three bits to add: 1, 1 and the carry 1. A half adder has only two inputs. It has no place for the carry that arrives. So it does only half of the job. The next lesson fixes this.

Check yourself

1. Which gate gives the sum in a half adder?

2. What are the carry and sum for 1 + 1?

3. Why is it called a half adder?

Practice

A half adder gets A = 1 and B = 0. What does each gate output, and what number do the two answer boxes show?

Show answer

XOR gives 1, so the sum is 1. AND gives 0, so the carry is 0. The boxes show 01, which is one.

Recap

  • Adding two bits needs two outputs: sum and carry.
  • Sum = A XOR B. Carry = A AND B.
  • A half adder cannot take a carry from the column before.