Let’s cover all the bases

Specifically bases 2 and 10

Jack Holland
Understanding computer science
4 min readFeb 9, 2014

--

This is an ongoing series. Please check out the collection for the rest of the articles.

For any aliens reading this, these are what human hands look like

We didn’t always have 10 digits in our numeral system. In fact, some ancient numeral systems didn’t even use digits the way we do now. The history of numbers is fascinating and we’ll certainly discuss it more later, but in this post I want to focus on one particular aspect of our modern numeral system: why we use 10 digits and why computers don’t.

As the above image of the hands suggests, we probably use 10 digits because we have 10 fingers, thereby making counting more convenient. But we don’t need to use 10 digits; we could use 9, 13, or 500. Obviously a 500 digit system would be a nightmare and would never be practical (I’m amazed the Babylonians accomplished so much with their whopping 60-digit system). But if we had 11 fingers instead of 10, we would probably have 11 digits; there’s nothing special or correct about 10 except that it matches our fingers.

This may sound very hypothetical and abstract, but it’s not. Why not? Because electronic computers don’t use 10 digits — they use only 2. In base 10, counting goes like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and then we run out of digits. When we run out of digits, we simply repeat the process, this time with a 1 before each digit: 10, 11, 12, … 19. Then we add a 2 before each digit: 20, 21, 22, … 29. I know this is really obvious, but I promise going over it will help you understand how base 2 counting works.

Predictably, we run into another problem after 99: we’ve run out of digits to add before each digit. But, as you know, we solve this by repeating the process, this time with a 1 before 2 digits: 100, 101, etc. When we run out of 3-digit numbers, we repeat the process with a 1 before the other 3 digits: 1000, 1001, and so on and so forth. By repeatedly adding digits to the left, we can represent any positive integer we want, no matter how big it is. This idea is called positional notation and is a very underrated invention.

Base 2 works the same way but with 2 numbers instead of 10. Here’s the first 20 numbers in both systems:

The first 20 numbers in base 10 (top) and base 2 (bottom)

As you can see, the first two numbers, 0 and 1, are identical in both systems. But after that, base 2 runs out of digits. So what does it do? It repeats the process, adding 1 before each digit, like this: 10, 11. Because there are so few digits in base 2, it runs out of them more frequently than base 10 does. After 10 and 11, base 2 again adds a 1 before each digit, otherwise incrementing the same as it has been: 100, 101, 110, 111. This pattern continues as you would expect. It’s important to recognize that base 2 and base 10 work the same way, the only difference being that base 10 has more digits.

Unfortunately, base 2 will never feel as natural to us as base 10. We’ve seen and used 10 digits all of our lives and trying to do the same math with just 2 digits is difficult for our brains to process. But that’s OK! Most of this low level math is handled by the computer anyway, so the most important thing right now is to understand the concepts behind base 2, even if those concepts are hard to work with.

You’re more than welcome to try out arithmetic using base 2 (and I’ll cover it pretty thoroughly when we get to circuitry) but that’s not our current focus. In the same vein, knowing how to convert between base 10 and base 2 is essential, but we’ll just assume there’s a way to do it and return to the problem later on when we have more tools at our disposal. Just recognize that base 2 is an equally valid way of representing numbers and that for every number in base 10, there is an equivalent in base 2 — and vice versa (actually, some weird problems pop up when converting floating point numbers between bases).

So what’s the point of discussing base 2? It turns out that in order to understand the next big topic, strings, you need to understand how a number can be represented as a sequence of 0s and 1s. As you may have just inferred, that’s exactly what we covered in this post! A sequence of 0s and 1s is just a number in base 2 and since any number in base 10 can also be represented in base 2, we’ve already solved this problem; if you want to convert a number into a sequence of 0s and 1s, simply convert it to base 2.

Image credit: hands

--

--