Different bases
In this post I'm going to talk about writing numbers in different bases.
Our usual way of writing numbers is in base 10. This means we represent a number as a sum of multiples of powers of 10. For example,
Writing numbers in another base means we replace 10 with some other number. For example, is written as in binary (base 2), because
We can indicate the base with a subscript: Note we're still using base 10 to write the subscript.
If the base is bigger than 10, we need symbols to go beyond the existing digits Traditionally, this is done using letters. So for instance, A represents 10, B represents 11, and so on, and F represents 15. For example, in "hexadecimal" (base 16) is because
How many words can you spell in hexadecimal? What are their decimal values? For example,
Here's a demo so you can see how this works with different numbers:
SourceThere's no mathematical reason to choose 10 as our base, it's just a cultural convention (probably due to us having ten fingers). For example, the Babylonians used base 60 ("sexagesimal"), and the Mayans used base 20 ("vigesimal"). Hexadecimal is used fairly often in computing.
The same idea works to the right of the "decimal point". For instance, because
Converting
Here's an implementation of that in code. We can check our work against the built-in Number.prototype.toString()
method.
Can you modify the above algorithm to handle decimals, e.g.
Uses
Although the vast majority of what we do is in base 10, there are a handful of places where we make use of other bases. Here are a few:
Colors
If you grew up in the 90s, you may remember [color=#FF0000]
or <FONT COLOR="#ffffff">
from forums and GeoCities. What do these mean?
On a computer, colors are represented by red, blue, and green (RGB) components, each between and Since this is between and when written in hexadecimal. For example, #FF0060 is red, green, and blue. Here's a demo where you can experiment with this in general:
SourceURLs
Very high bases are sometimes used to make short URLs, e.g. https://old.reddit.com/11jznte/ or https://youtu.be/dQw4w9WgXcQ. In their database, this thread has some numeric ID like 1298482891
, and 11jznte
is that number written in some base. I'm not sure exactly which base they chose: if we use capital and lower letters, the digits 0–9, and hyphens and underscores, then we get
as a base. But it's best to omit e.g. capital O and lowercase l, so we don't get confused between 0O1l
, so in practice it's more likely to be base 62 or smaller.
What does it mean?
So, a given number can be represented many different ways. What can we learn about a given number by writing in various different bases? Let's look at a few different examples of this, and then a conceptual way of organizing it.
Rationality
We have names for different kinds of numbers.
- the natural numbers are
- the integers are
- a rational number is one that can be expressed as a ratio of integers. For example, and so on.
- numbers which aren't rational are called irrational. For example, and are irrational.
Rationality can be seen in the digit representation of a number: a rational number will always have a repeating pattern of digits. For example,
which we write as
This includes the case of a terminating expression, which we can think of as a repeating In fact, every rational number has a terminating expression in some base. For example, we have
which terminates in bases 3 and 6 but repeats infinitely in base 10.
Irrational numbers, on the other hand, never fall into a repeating pattern. (This doesn't mean there's "no pattern" to their digits, just that it can't be expressed so simply.)
Last digits
Let's start by thinking about what the last digit of an integer written in binary means. The numbers through written in binary are
Notice that: the last binary digit of a number tells us whether it's odd or even!
In many situations, this is all we need to know about the number. For example, suppose you leave a room with the lights on, and come back later and the lights are off. You know that the light switch must have been flipped an odd number of times, but the exact number of times isn't relevant.
In general: the last digit of a number in base is its remainder when divided by
What about, say, the first digit? It turns out that this is harder to interpret. To see why, let's consider two addition problems, where some of the numbers are covered up.
For example, the first of these could be either of the concrete problems
Although these give different answers, the last digit is the same between the two answers. But in the second case, we can't pin down any of the digits for sure, not even the tens. For example, we could have either of
At most we can say that the middle is either or
In other words: to figure out the last digit of you just need to know the last digit of and of But to know the second-last digit of you need to know the last two digits of and since there could be carries from the last digit.
Knowing the last digits of a number written in base is the same as knowing its remainder when divided by
How do different bases relate? Let's write the last digits of the numbers through in bases and
Notice that: knowing the last digit of in base is the same as knowing its last digit in base and in base
Let's try this for and
Here we don't have quite the same pattern as above: knowing the last digit in base isn't the same as "knowing the last digit in base and also in base Instead, knowing the last digit of in base is the same as knowing its last two digits in base .
If and have no factors in common, then knowing the last however many digits in base is the same as knowing the last that many digits in bases and
At the opposite end, knowing the last digits in base is the same as knowing the last digits in base
The function analogy
Writing a number in base
looks very similar to writing a polynomial in one variable
For example, the number
looks very similar to the polynomial
In particular,
So, is it possible to either view
- polynomials as "numbers in base or alternatively
- integers as "functions in the variable
The main difference between the two situations is that to add two polynomials, you just add the coefficients together:
but when adding two numbers, we have to carry:
So in this analogy, polynomials are actually easier to work with than numbers! So we should take the second of the above suggestions: that is, try to understand integers as ``functions in the variable ''.
There's a ton of math research around trying to flesh out this analogy; it broadly goes under the name of the "function analogy" or the "philosophy of the field with one element" (but it will take quite a while to explain that name). The stuff I think about is part of or adjacent to one of the main approaches to doing so (but there are several others). Basically, we understand polynomials very very well, so we could try to take the tools we have for working with polynomials and translate them through this analogy to get very powerful tools for understanding integers and prime numbers and so on.
Carrying is just one way that base expansions are harder to work with than polynomials. Another major one is that we can contemplate polynomials in multiple variables, e.g.
We really don't know what the analogue of this would be for numbers, i.e. how to "mix bases". In the past 10 years, there's been an explosion of activity in this area, and we now have very precise glimpses of parts of what this ought to be. These are very exciting, but we definitely don't have the full picture yet.
What would be a satisfactory answer to "fleshing this out"? And relatedly, what would such a thing be good for?
The Riemann hypothesis is widely considered the most important unsolved problem in math. It's a technical statement about complex numbers, but basically it gives an extremely precise description of the distribution of prime numbers, i.e. what is the probability that a randomly chosen number will be prime? There's a "polynomial" version of the Riemann hypothesis, which is still extremely difficult, but was proven in 1974. So one proposed strategy for proving the original Riemann hypothesis is to take that proof and translate it through this analogy—but that gets stuck due to not being able to talk about "multi-base numbers".
Conversely, this provides a way of assessing claims of "making sense of the function analogy". There's lots and lots of ideas about how to do this—but until we can prove the Riemann hypothesis, we haven't found the "one true way" (if there is one).
I'll devote a future chapter to explaning the function analogy in more detail.