How can we get our half adder to include a carry?
Let’s start by examining when we get a carry:
- 0 + 0 ⇒ 0
- 0 + 1 ⇒ 0
- 1 + 0 ⇒ 0
- 1 + 1 ⇒ 1
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:
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 with a combination of a turn
and a switch
:
This behaves exactly like the single xor . Now, to push the carry backwards, let’s replace the switch
with a canute
:
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 with a long turn
:
Now we’re getting somewhere! But… what happens when we try to do 1 + 1 and we already have a carry?
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:
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)
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