Let’s say you have two binary numbers you want to add together. That’s two inputs. With two binary numbers, zero and one, you get two different sums: 0+0=0; 1+0=1; 0+1=1; and 1+1=0.

1+1=0?

0 is the sum, but you have to create another output, carry. And you have to carry it somewhere. So now you have two more inputs, carry in and carry out.

Check this out:

Let’s start by adding two binary bits. Since each bit has only two possible values, 0 or 1, there are only four possible combinations of inputs. These four possibilities, and the resulting sums, are:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10

Whoops! That fourth line indicates that we have to account for two output bits when we add two input bits: the sum and a possible carry. Let’s set this up as a truth table with two inputs and two outputs, and see where we can go from there. . .

The Carry output is a simple AND function, and the Sum is an Exclusive-OR. Thus, we can use two gates to add these two bits together. The resulting circuit is shown below.

A B CARRY SUM
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0

I like demonstrating this with pennies. Penny down=0; penny up=1. When carrying, the movements are complex, but not impossible for a hobby level robotic, perhaps not even for a vending machine. Ooh, how about a vending machine that registers your number!

Put two pennies in a slot–11–that’s three in binary. The pennies create a circuit and the sum is written on the screen. A lever pushes the pennies down and the operation is performed.

You then get a fortune cookie printout of the sum.

If anything, it might be a good way of getting rid of those extra pennies.