✖

Converting between number systems

How to convert numbers from base 10 into other number systems, and how to convert numbers from other systems back into base 10.

What is a number system

We normally work in base 10, the decimal system. It has ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. What marks out base 10 is that when we multiply a number, say 57, by 10, we move one place to the left – we need one more digit to write it: 570.

We can have other number systems too. An octal system (base 8) would contain only the digits 0, …, 7. The expression 7 + 1 would then equal 10, because base 8 has no digit 8. A hexadecimal system (base 16) would have the digits 0, 1, … 14, 15. Instead of digits greater than 9 we sometimes use letters, so base 16 has the digits 0, …9, A, B, C, D, E, F.

Surprisingly, we meet other number systems in everyday life. Take time – we count seconds and minutes in base 60. Every moment of the day can be written as a three-digit number in base 60. The first digit gives the hours, the second the minutes and the third the seconds. If we choose a colon as the separator, we get, for example, 14:05:59. Notice that when we add one second to this time we do not get 14:05:60 but 14:06:00 – because 60 is not a valid digit in base 60.

Converting from base 10 to base 2

Suppose we have the number 70 on paper and want to convert it into binary, base 2. The principle is fairly simple: we keep dividing the number by 2 until we reach zero, writing down the remainder each time. To convert into another system, for example base 16, we divide by 16. To convert into base 6, we divide by 6. In practice it looks like this:

70÷2=35⟶0(remainder)35÷2=17⟶117÷2=8⟶18÷2=4⟶04÷2=2⟶02÷2=1⟶01÷2=0⟶1

The remainders give the number in base 2. But we read them from the bottom up, not from the top. So 70 in binary is 1000110.

Converting from base 2 to base 10

To go the other way we do this. Take the number 1100010 and convert it into base 10. This direction is easier – we just work out this sum:

11000102=1⋅26+1⋅25+0⋅24+0⋅23+0⋅22+1⋅21+0⋅20

Each term has the form x · 2i, where x is a digit of the original binary number and i goes up by one at a time from the right. Since we are converting 1100010, the sum looks like this:

11000102=1⋅26+1⋅25+0⋅24+0⋅23+0⋅22+1⋅21+0⋅20

The number 1100010 has seven digits, so the exponents of 2 go 6, 5, …, 1, 0. After working out the powers and multiplying we get

11000102=64+32+2=98.

Why does this method work?

We can demonstrate it in base 10. What do the digits in a number such as 7,384 really mean? The digit 4 gives the number of units, 8 the number of tens, 3 the number of hundreds and 7 the number of thousands. So we can write

7384=7⋅1000+3⋅100+8⋅10+4⋅1

We can tidy this up so that instead of 100, 10 and 1 we always have a power of ten. Since 100 = 1, 101 = 10 and so on, we can write

7384=7⋅103+3⋅102+8⋅101+4⋅100

We can describe any number in base 10 in the same way, and the terms have the form x · 10i, where x is a digit from 0 to 9 – there are ten such digits. The value i is a non-negative integer that gives the place value. If i = 0, the term gives the units, and if i = 2 it gives the hundreds (because 102 = 100).

Now let’s try converting 7,384 from base 10 into, er…, base 10. It will make sense. We divide 7,384 by 10:

7384÷10=738⟶4(remainder)738÷10=73⟶873÷10=7⟶37÷10=0⟶7

If we read the remainders from the bottom up, we get 7,384 – the number we started with, which we were trying to convert into the … same system.

To describe binary we do exactly the same – all the terms have the form x · 2i, where x is the digit 0 or 1. Again, i gives the place value. Just as repeatedly dividing by 10 gives us the digit in each place of a number in base 10, repeatedly dividing by 2 gives us the digit in each place in base 2.

Notice also that when we divide a number by 10 and look at the remainder, the remainder is always in the interval [0, 9]. If we divide by 2, the remainder can only be 0 or 1.

Converting to other bases

The method above for converting from base 10 to binary is so general that it works for other bases too. To convert 185 into base 16, we just divide by 16:

185÷16=11⟶9(remainder)11÷16=0⟶11

In base 16, 185 would be written as (11, 9). Instead of “digits” above 9 we usually use letters, so 10 = A, 11 = B, 12 = C, … So we can write 185 in base 16 as B9.

In the same way we can convert B9 from base 16 into base 10:

B916=11⋅161+9⋅160=11⋅16+9=185