Using logic gates, we’re now going to build a device that can add two numbers together — an adder. This is going to be a key component of any computer.
addition
Forget roons for a moment — how do we add numbers together?
If you had to solve 27 + 46
, you’d probably do something like:
- Add the last two digits,
7 + 6 = 13
. So the last digit is3
, and we carry the 1. - Add the next two digits,
2 + 4 = 6
. Then add our carry,6 + 1 = 7
- Putting these together, we get
73
.
In other words, our algorithm (recipe) for adding numbers is:
- Starting with the lowest column, add the two digits together.
- If the result is bigger than 10, carry the 1 into the next column.
binary addition
This algorithm doesn’t just work for base ten — it works in all bases.
Remember how we used base two as our scheme for encoding numbers in roonish? That was a practical decision for giving us sensible names for the numbers — but it also means we can use long addition to add our numbers together, just like with base ten.
In base two, 27 + 46
is 011011 + 101110. Starting with the right-hand digits, and walking backwards:
- 1 + 0 = 1
- 1 + 1 = 10 — take the 0, carry the 1
- 0 + 1 + C = 10 — take the 0, carry the 1
- 1 + 1 + C = 11 — take the 1, carry the 1
- 1 + 0 + C = 10 — take the 0, carry the 1
- 0 + 1 + C = 10 — take the 0, carry the 1
- We now have a leftover carry of 1, so this goes at the start of the number.
Our result is 1001001 — which is the binary representation of 73
.
summary
So there are two components to addition:
- Adding the digits
- Performing the carry
To build an adder out of roons, we’re going to tackle these tasks one by one.
continue