carry

How can we get our half adder to include a carry?

Let’s start by examining when we get a carry:

  • 0 + 00
  • 0 + 10
  • 1 + 00
  • 1 + 11

The truth table is , which is just an AND gate. In other words, an AND gate performs a physical representation of calculating the carry.

Let’s look again at our half adder:

00/0000/00
loading…

partial adder 1

Conveniently, the highlighted cell functions as an AND gate, so we’re already computing the carry for free! All we need is a way to push this carry into the next calculation.

To begin with, remember that we can replace our xor xor with a combination of a turn turn and a switch switch:

00/0000/00
loading…

partial adder with switch

This behaves exactly like the single xor xor. Now, to push the carry backwards, let’s replace the switch switch with a canute canute:

00/0000/00
loading…

partial adder with switch back

Now whenever there’s a carry, it flows back into the next calculation.

It’s a good start, but if we try to push a carry back when there’s a left-hand input, the marbles will collide. To avoid this, let’s replace our turn turn with a long turn long turn:

00/0000/00
loading…

partial adder 2

Now we’re getting somewhere! But… what happens when we try to do 1 + 1 and we already have a carry?

00/0000/00
loading…

partial adder 3

The leftmost marble is going to spill into the ejected cell. We need to handle this — but where should it go?

Let’s think about what this case means. Effectively, we want:

  • 1 + 1 + C= 1, carry 1

The centre and rightmost marble are already performing 1 + 1 = 0, carry 1 — the leftmost marble doesn’t affect them. So the carry is correctly handled, but the output digit is currently a 0 and we need it to be a 1.

Therefore, what we need to do is take our spare marble and connect it up to the output, so that it functions as a 1.

Plugging it all together:

00/0000/00
loading…

adder

The indicated cell is the output. It gets its value from two sources merging together:

  • The normal output of our XOR gate
  • The third marble from the special case of 1 + 1 + C

testing it out

We’ve built an adder — now try it out! Supply it with a pair of binary numbers and confirm it gives you the correct result. Here are some examples to try:

  • 0101 (5) + 0110 (6) = 1011 (11)
  • 11100 (28) + 10111 (23) = 110011 (51)
note

Remember to start with the lowest digit when inputting a number.

recap

We have an adder! From just moving marbles around using some simple shapes, we’ve created a device that can add arbitrarily large numbers together.

In the next tutorial we’ll examine our adder’s behaviour in more detail.

continue