So in this post I talked a little bit about number bases and how they’re used in floating-point expansions. I thought I’d go a little bit more into them, since I didn’t really explain how they work.
So the number base we’re all familiar with is decimal, obviously. But not many people realize how arbitrary a choice that seems. Consider the number 10, base 10. By what reasoning do we assume that a one followed by a zero represents ten units? If you remember back to grade school, the 1 is in the “tens” place and the 0 is in the “ones” place. So what we’re actually saying when we write the notation “10” (base 10) is that we have one group of ten units, and zero groups of ones, which comes out to ten units. Or, put in another way, number base notation is a convenient way to express complicated integral additions and multiplications. Remember, .
To really appreciate the arbitrary nature of our number system, you must distinguish between what we call or name things, and what the thing actually is. Notice that when I write “20”, you immediately associate that notation with a specific number, namely the sum of the number 1 a certain number of times.
But what is “20 base 10”, which I’ll call , in binary? It happens to be . How do I know?
Well take a number in decimal, say . From our grade school understanding, we know this means we have one group of ones, one group of tens, one group of hundreds, one group of thousands, and one group of ten-thousands. Or, put in another way, one group of , one group of , one group of , one group of , and one group of . When we go from to , you can see that we overflow into the tens spot, i.e. when we go from to .
So by base 2, we mean the following. The ones place in binary is analogous to the ones place in decimal, with one distinction. Since , it’s still a ones place, but because it’s in base 2, when we get to , we overflow into the next place (or the “twos place”). So is represented as . When we get to we overflow into the “fours place”. When we get to , for some natural number n, we overflow into the “n’s place”.
So if we wanted to write in binary, we find the closest place to 20 in binary, which is , and put a 1 there. is more than , so we look for the closest place to 4, which is , and put a 1 there. Thus we get (and pardon the poor spacing; just line up the |’s):
Places: 16 | 8 | 4 | 2 | 1
Number: 1 | 0 | 1 | 0 | 0
And the number we get is 10100 (base 2), which equals 20 (base 10).
Let’s do another example. Let’s write in base 3.
Places: 81 | 27 | 9 | 3 | 1
Number: 0 | 2 | 1 | 1 | 2
In other words, (27×2)+(9×1)+(3×1)+(1×2) = 54+9+3+2 = 68. So 2112 (base 3) = 68 (base 10).
Number bases get really interesting when you start making them very large or negative. For instance, let’s look at the in base 200:
Places: 16e8 | 8e6 | 40000 | 200 | 1
Number: 0 | 0 | 0 | 2 | 63
(Here, 16e8 means 16 x 10^8 and 8e6 means 8 x 10^6.) Base 200 is very interesting because of its ones place. What does the notation “63” mean in this context? It’s obviously base 10. But that makes no sense, as we’re in base 200. This means we need to define new numbers. In fact, we need to define 200-9 new numbers. Why? Because once we get to 10, we’ll mess up our notation otherwise. Consider if we just wrote this number (in base 200) as 263. 263 (base 200) is actually (2*40000)+(6*200)+(3*1) = 81203 (base 10).
How do we define new numbers? Pretty easily. Let the symbol “&” denote 63 (base 10). Thus, 2& (base 200) = 463 (base 10). A real-life analogy to this can be found by looking at the hexadecimal system, which is used in computing. The hexadecimal digits are 1 through 9, and a, b, c, d, e, and f (representing 10, 11, 12, 13, 14, and 15 in base 10 respectively).
Let’s look at base 1, just for kicks. Obviously all the place values are 1s. Which is weird. Remember, in base 10, any of the places can only go up to 9. Once we go higher than 9, we overflow to the next place. In general, for base n (where n is integral, not including zero), each place can only go up to |n|-1 before overflowing into the next place. So for base 1, each place can only go up to 1-1=0. Which means our notation fails at capturing a base 1 system. We may define a special system in this case, which is sometimes done. Define a number in base 1 as successive 1’s representing the number of units it has. So for example, =, for . In other words, we’re just counting one at a time. So we could replace the 1’s with anything, as long as they’re the same. They’re just hatch marks, so to speak.
Let’s look at an example of a negative number base, say base -2. The place values of base -2 look like this:
Places: (-2)^4 | (-2)^3 | (-2)^2 | (-2)^1 | (-2)^0
Places: 16 | -8 | 4 | -2 | 1
This is very interesting. What this means is with a negative number base we can represent both negative and positive numbers using only positive numbers. For instance, = , but = . Isn’t that weird? . From our ethnocentric decimal intuition, this looks mighty strange. If there existed a culture that used base -2, they would find it just as intuitive as we find base 10. And they would probably scoff at the fact that we have to have a separate symbol for negative numbers in base 10!