# Binary addition (2)

We’ve constructed a computer out of water tubes and buckets in the first post that can add 2 numbers if those numbers happen to be 0 or 1 (this is called a half adder circuit). But what if you wanted to add say 1 and 2? What now?

First, we have to pick how many input tubes we’re going to have. This determines how big the inputs can be. Let’s say 4 input tubes, so that each of the 2 numbers we add can have 2 binary digits. (If we had say 30 input tubes, each of the two numbers that we add could have 30 / 2 = 15 binary digits).

With that setup, we can choose from 0 = 00, 1 = 01, 2 = 10, or 3 = 11 for each our inputs. And at most the sum could be 3 + 3 = 6 = $2^2 + 2^1 + 2^0$ = 111. So we need 3 buckets to represent the output.

Another way to think about it is that our computer will represent all numbers (inputs and outputs) using 2 binary digits. The third bucket in the output is a boolean that tells us if there’s been an overflow error in our computation, i.e. the sum of the two numbers we tried to add is too big for the space that we’ve reserved to represent numbers.

For example, in the case of adding 3 + 3, or 11 + 11 in binary:

```
carry: 11
11
+11
---
110
```

We’d get an answer of 10 = 2 and the third bucket would be full, which would tell us not to trust the answer that we got.

Let’s label the least significant digit of the first input A0, the least significant digit of the second input B0 and the least significant digit of the sum S0. Similarly, call the second most significant digit of the inputs and the sum A1, B1 and S1 respectively. For example, if we add 1 = 01 and 2 = 10, then A0 = 1, A1 = 0, B0 = 0, B1 = 1 and the sum should be 3 = 11, so S0 should be 1 and S1 should be 1. Let’s call the third bucket of the output the “E” for error bucket, which is full when the sum is too big to store in 2 binary digits.

Here’s our computer:

If we wanted to add numbers with more binary digits, we could just imagine continuing the pattern by replacing the E bucket with a $C2_{in}$ bucket and having that go into another tank with tubes flowing out to a S2 bucket and a $C3_{in}$, which feeds into another replica and so on. Note that an E bucket is just like a $Ci_{in}$ bucket with the difference that we’re at the end of our computation for the E bucket.