← Teacher guide

Adding with gates

Students build a half adder from XOR and AND, add 4-bit binary numbers on a chain of full adders and watch the carries ripple, then build a full adder from gates (AC9TDI8K04 node 3, extended; the kit names adder circuits as going further).

From gates to a processor · Building with gates · about 45 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 7 min · Worked example 10 min · Vary 10 min · Practise and Make 18 min

Before class

Try the boards yourself.

The one idea: one column of an addition is a small truth table (sum and carry), so gates can add. Students have met the half adder in Data representation's logic gates lesson; here they build it and then go further.

Column addition in base ten first helps: 5 + 5 writes 0 and carries 1, exactly like 1 + 1 in binary.

The 4-bit adder on the board is drawn as full adder boxes; the gates inside each box are the ones students build in the Make.

Running the lesson

  1. Predict: students who chose 2 hold Sam's misconception.
  2. Try: ask which gate makes the carry and why.
  3. Worked example: write the carries above the columns, as in base ten.
  4. Vary: after overflow, ask where the fifth bit would have to go.
  5. Make: let students reuse the first XOR for the carry; compare gate counts.

The hard part (on purpose)

The full adder Make is hard on purpose: it is the first circuit with three inputs and two outputs. Point at the wanted columns and let students build the sum first, then the carry.

When students get stuck

What you will seeA question to askThe fix
A student writes 2 in a binary sum (Sam's mistake).Which digits can binary use?1 + 1 = 10: write 0, carry 1.
A student's full adder sum is right but the carry is wrong.Which rows need a carry? How many 1s does each have?Two or more 1s: (A AND B) OR ((A XOR B) AND CIN).

Answers to the checks

  1. 1 + 1: In binary, what is 1 + 1?
    10 (two): write 0 in this place and carry 1 to the next, just as 5 + 5 in base ten writes 0 and carries 1.
  2. Try: build a half adder: Build the half adder: S (sum) and C (carry) for two bits. Every row should match.

    Sum = A XOR B, carry = A AND B. The last row, 1 + 1, gives S 0 and C 1: binary 10.
  3. Place by place: Add 0110 + 0011 (6 + 3) the same way. What is the sum, in four bits?
    1001
    Ones: 0 + 1 = 1. Twos: 1 + 1 = 0, carry 1. Fours: 1 + 0 + carry 1 = 0, carry 1. Eights: 0 + 0 + carry 1 = 1. 1001 = 9.
  4. Find the mistake: Sam adds 0101 and 0011. Click the line where it first goes wrong.
    line 2
    Line 2: binary has no digit 2. 1 + 1 = 10: write 0, carry 1. The answer is 1000 (8).
  5. Why three inputs?: A half adder adds two bits. Why does a full adder need three inputs?
    It also adds the carry coming in from the place to its right
    Every place except the first may get a carry from the right: A + B + carry in.
  6. No carry: Set A = 9 and B = 6. Does any place carry?

    1001 + 0110 = 1111: each place has only one 1, so nothing carries. 15.
  7. One carry: Find two numbers whose sum has exactly one carry, and still fits in four bits.

    For example 1 + 1: the ones place carries into the twos, and that is all.
  8. Overflow: Now make the last carry fall off the end: a sum that needs a fifth bit.

    Overflow: four bits hold up to 15, so the sum needs another bit. In an 8-bit register, 255 + 1 gives 0 with a carry.
  9. Every place: Make every place carry.

    For example 15 + 1: the carry ripples through every place, like 9999 + 1 in base ten. Rippling takes time, so real processors use tricks to look ahead.
  10. Add: Add 0011 + 0011 in binary (four bits).
    0110
    3 + 3 = 6 = 0110.
  11. How many adders?: How many full adders does a processor need to add two 8-bit numbers in one go?
    8: one for each place
    One full adder per place, side by side. (The first can be a half adder: nothing carries into it.)
  12. Review: overflow: Review: an 8-bit register holds 255. You add 1. What does it hold?
    0, and a carry falls off the end
    11111111 + 1 = 100000000: the ninth bit has nowhere to go, so the register holds 0. That is overflow.
  13. build a full adder: Build a full adder: inputs A, B and the carry in (CIN); outputs SUM and CARRY. Every row should match.

    Five gates: two XORs for the sum, two ANDs and an OR for the carry. Line up four of these and you have the 4-bit adder from the board.

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: carries › No carry

Open task: any program that does what the step asks.

Vary: carries › One carry

Open task: any program that does what the step asks.

Vary: carries › Overflow

Open task: any program that does what the step asks.

Vary: carries › Every place

Open task: any program that does what the step asks.

build a full adder

Open task: any program that does what the step asks.

Stretch and support

Stretch: Subtraction: look up two's complement. How could the same adder subtract?

Support: A column-addition frame with a carry row above, for binary.

Exit ticket

Add 0110 + 0101 in binary. Which places carried?

1011 (11). Only the fours place carried (1 + 1 = 10).

What each step is for

Where it leads

Next: Remembering a bit (latches and registers).

Links: Data representation › Bits all the way down (overflow); Inside a computer (the processor's speed).