Number Systems

As a kid, I was fascinated by roman numerals. After learning how to write numbers in school and getting used to how they work, I found it so strange that there were other way of counting things. Or rather, there are other ways ofwriting what I was counting in a way that someone else, if they knew the rules, could understand. In this same way, computers count numbers in a completely different way by only using the digits "0" and "1" to represent any and all numbers we can think of. These different ways of writing numbers - systems of notation - are fascinating to explore and in this article we'll take a deep mathematical exploration into what number systems are and how they are used in computers specifically. Before we do that, we'll get some vocabulary out of the way so what we describe in this article is less confusing and has some internal consistency.

What is a Number System?

A number system is a series of rules we create for representing and manipulating numbers. This includes rules for counting them, performing mathematical operations like addition, subtraction, division, and multiplication, and representing fractions. To start this exploration, we'll start with the simplest way of counting numbers - Base 1, also known as the Unary Number System, also visualized with symbols of tally marks.

Unary Number System - Base 1

The Unary Number System has only one symbol in it - "1". So if we want to represent the number two, we would write "11" - two digits next to each other of the symbol "1". And for three - "111". For fifteen - "111111111111111". If you haven't caught on yet, in order to represent a given number we write an equal amount of digits with the "1" symbol to represent that number. As you can imagine, this gets really inefficient, really quickly, for larger numbers. Also, how would we represent numbers smaller than 1? Draw half of "1" symbol? Or the number one million? I'd probably spend all day writing it out! Thankfully, we can write computer programs to do this heavy lifting for us. Try out the Unary Number Translator below. And, as you may notice, there's no need for the symbol "0" because to represent zero all we need to do is not write anything.

1.0Unary Conversion
5
++
=1
1
1
1
1
1

Binary Number System - Base 2

The binary number system is the mathematical language of computers. Every computer is made up of bits - containers that hold either the symbol "0" or "1" - and can be used to represent any number. The rules for binary get a little more complicated than Base 1. In order to represent the number two we actually do the same thing we do to go from nine to ten. In order to do this, what we do is turn the "9" into a "0" and then write a "1" to the left of it - so it looks like "10". In order to write two in binary, we turn the "1" into a "0" and write a "1" to the left of it. So "10" in binary means the number two, not ten! Why is this?

The reason "10" doesn't always mean the number ten is the same reason "bat" is both an animal and the name of the stick used to hit a baseball. We create rules in language that results in words meaning different things depending on how they are used. In this case, the symbols "1" and "0" are used to mean different numbers depending on the base number used. Therefore, "10" means ten in our decimal number system (Base 10 - what we use everyday), while "10" means two in the binary number system (Base 2). In fact, in every different base number system, we use "10" to represent that number. See the table below to see how different number systems represent numbers.

Number SystemBase NumberSymbols UsedWriting Ten
Base 1111111111111
Base 220,11010
Base 330,1,2101
Base 440,1,2,322
Base 550,1,2,3,420
Base 660,1,2,3,4,514
Base 770,1,2,3,4,5,613
Base 880,1,2,3,4,5,6,712
Base 990,1,2,3,4,5,6,7,811
Base 10100,1,2,3,4,5,6,7,8,910
Base 11110,1,2,3,4,5,6,7,8,9,AA
Base 12120,1,2,3,4,5,6,7,8,9,A,BA
Base 13100,1,2,3,4,5,6,7,8,9,A,B,CA
Base 14140,1,2,3,4,5,6,7,8,9,A,B,C,DA
Base 15150,1,2,3,4,5,6,7,8,9,A,B,C,D,EA
Base 16160,1,2,3,4,5,6,7,8,9,A,B,C,D,E,FA

The "Base Number" in Base Number Systems

As you can see in the table above we can use any number we want as the "base number" in the base number system. To reiterate, "10" is meant to be how the base number is written in that base number system. "10" in Base 3 means the number three. In Base 4, "10" means four. In Base 8, "10" means the number eight. And, as stated earlier, "10" in Base 10 means ten! So the bigger question may be, why do we do this? Why do we have "10" mean different things and even create different Base number systems?

The primary reason for this convention can be seen when we looked at the unary number system - Base 1. In order to represent larger and larger numbers, we started writing more and more 1's right next to each other. To reduce the number of symbols used, we created the concept of "place value" so that numbers bunched together like a word can mean something different from the numbers individually. How, in our normal number system, "1" means one, "2" means two, but "12" means twelve.. It doesn't mean one and two (which would be three) but rather something entirely different. This notational rule allows us to write larger numbers with fewer symbols. And there's an underlying logic to this system. But before we get there, let's do a deeper dive into place value.

Place Value - Base Number's Complement

If the choice of base number is peanut butter, place value is its jelly. It doesn't make sense to have one without the other. Place value is how we assign meaning to numbers when we put them together like a word. "123" is one hundred twenty three in our decimal number system - Base 10. Or, in other words, one hundred plus twenty plus three - "100 + 20 + 3". Even though we don't see those zeroes in the number indicating how big of a number it represents, it's place in relation to the other numbers tells us what it's value is.

1.1Place Value
1
2
3
4
1,000
+
200
+
30
+
4
11000
+
2100
+
310
+
41
1103
+
2102
+
3101
+
4100

As you can see above, place value in our Base 10 decimal number system tells us what each number represents and how we could break the number up if we wanted to represent it differently. We can't simply take "4675" and split it up into "46" and "75" - that wouldn't be equivalent. But "4600" and "75" would be equivalent. Why? Place value. And it's this concept that we can use to represent place value in other base number systems. But before we start representing numbers in other base number systems, we're going to dive into that magical math behind place value and their relationship to exponents.

1.2Place Value with Base 10
1
2
3
4
1,000
+
200
+
30
+
4
11000
+
2100
+
310
+
41
1103
+
2102
+
3101
+
4100

As you can see, the base number is exponentiated by the place value. In the case of the number "4675" in Base 10, the "6" is actually "6 * 103" because it's the third digit in the number. This same process holds when we change the base number. See below how when you change the base number it changes the number that gets exponentiated? It's important to note that for the sake of simplicity the exponents themselves are in Base 10 - i.e. 212means the exponent is twelve. We could write our exponents in the same base but that makes understanding the concept a little more difficult. Baby steps! In the diagram below we start with a number in Base 2 (notice the "2" in 11112 - that subscript tells us the base), expand it out in Base 10, perform the math in Base 10, and show what the number would be after all arithmetic is performed in Base 10. This is essentially a conversion from Base 2 into Base 10.

1.3Base 2 to Base 10
=10
(1101)
+
(3100)
=10
(110)
+
(31)
=10
10
+
3
=10
1
3

This patterning holds the key for how we can convert any number from one base into another base. In the diagram below we take a number that's in Base 10 and show the process for how we convert it into Base 2. The key is knowing the max number that can be represented by each place value and subtracting that number from the original number you want to represent. You repeat this process until you get to the rightmost place value digit.

1.4Base 10 to Base 2
=2
(123)
+
(122)
+
(021)
+
(120)
=2
(18)
+
(14)
+
(02)
+
(11)
=2
8
+
4
+
0
+
1
=2
1
1
0
1

Going Deeper

With this deep dive into number systems and how they are defined, we've discovered a bunch of relationships between the way we write numbers and what they mean mathematically. In another article we'll dive into bases larger than Base 10, and especially their usefulness in computer programming. If you're interested in learning more about Base 2 and how it's used in bits and bytes, check out this article. If you're interested in how Base 2 is used in boolean algebra to represent logic - TRUE, FALSE, NOT, AND, OR - I've got another article for you. If you're interested in diving into the deep end and learn how a programming like LISP uses all of the above to make computers do what they, you'll want to check that out here.