Conversions of systems

How to convert numbers from the decimal system to other systems and vice versa.

What is the number system

We commonly work with the decimal system. This system has ten digits, 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The decimal system is characterised by the fact that when we multiply a number, for example 57, by ten, we move up one order of magnitude - we need one more digit to describe that number: 570.

We can have other number systems; such an octal system would contain only the digits 0, …, 7. The expression 7 + 1 would be equal to 10, because we don't have the digit 8 in the octal system. The hexadecimal system would have the digits 0, 1, … 14, 15. Sometimes we use letters instead of digits that are greater than 9, so a hexadecimal system would have the digits 0, …9, A, B, C, D, E, F.

Surprisingly, we encounter other number systems in everyday life. For example, we count time - seconds and minutes - in the hexadecimal system. Every moment of the day can be written as a number in the hexadecimal system of three digits. The first digit indicates hours, the second minutes, the third seconds. If we choose a colon to separate the digits, we have, for example, the number 14:05:59. Note that if we add one second to this time, we do not get the time 14:05:60, but we do get the time 14:06:00 - because the digit 60 is not a valid digit of the hexadecimal system.

Converting from decimal to binary

Let's have the number 70 on the paper. We now want to convert this number to binary, the binary system. The principle is quite simple, we keep dividing the number we want to convert by two until we reach zero, writing down the remainders after the integer division. If we want to convert a number to another system, for example hexadecimal, we divide by hexadecimal. If it's in hexadecimal, we divide by six. So in practice, it looks like this:

$$\begin{eqnarray} 70 : 2 &= 35 & \longrightarrow 0 \quad(\mbox{ remainder after division })\\ 35 : 2 &= 17 & \longrightarrow 1\\ 17 : 2 &= 8 & \longrightarrow 1\\ 8 : 2 &= 4 & \longrightarrow 0\\ 4 : 2 &= 2 & \longrightarrow 0\\ 2 : 2 &= 1 & \longrightarrow 0\\ 1 : 2 &= 0 & \longrightarrow 1 \end{eqnarray}$$

The resulting number in the binary system is the remainder after division. But we don't take the remainders from the top, we take them from the bottom. So the number 70 in binary is 1000110.

Converting from binary to decimal

In reverse, we would convert as follows. Let's take the number 1100010 and convert it to decimal. This direction is easier, just calculate this sum:

$$ 1100010_{10} = 1\cdot2^{6}+1\cdot2^{5}+0\cdot2^{4}+0\cdot2^{3}+0\cdot2^{2}+1\cdot2^{1}+0\cdot2^{0} $$

Each addend is of the form x · 2i, where x is a digit from the original binary number and i is incremented by one each time from the right. So since we are converting the number 1100010, the sum looks like this:

$$ 1100010_{10} = \fbox{1}\cdot2^{6}+\fbox{1}\cdot2^{5}+\fbox{0}\cdot2^{4}+\fbox{0}\cdot2^{3}+\fbox{0}\cdot2^{2}+\fbox{1}\cdot2^{1}+\fbox{0}\cdot2^{0} $$

The number 1100010 has seven digits, so the powers of two will be successively 6, 5, …, 1, 0. After multiplying and exponentiating, we get the expression:

$$ 1100010_{10} = 64 + 32 + 2 = 98. $$

Why does this work?

We can demonstrate this on the decimal system. What do the digits in a number, such as 7384, actually mean? The digit 4 indicates the number of ones, the digit 8 the number of tens, the digit 3 the number of hundreds, and the digit 7 the number of thousands. So we can write that

$$ 7384 = 7\cdot 1000 + 3\cdot100 + 8\cdot 10 + 4\cdot 1 $$

We can further modify this expression so that we don't use the numbers 100, 10 and 1, but always have some power of ten in there. Since 100 = 1 and 101 = 10 etc. are valid, we can write

$$ 7384 = 7\cdot 10^3 + 3\cdot10^2 + 8\cdot 10^1 + 4\cdot 10^0 $$

We are able to describe each number in the decimal system in the same way, while the individual addends have the form x · 10i, where x is the digit from 0 to 9, these digits being ten. The value of i is then some positive integer that gives the order. If i = 0, then the adder gives units, if i = 2, then it gives hundreds (because 102 = 100).

Now let's try to convert the number 7348 from the decimal system to, uh..., the decimal system. It'll make sense. We'll divide the number 7348 by 10:

$$\begin{eqnarray} 7348 : 10 &= 734 & \longrightarrow 8 \quad(\mbox{ remainder after division })\\ 734 : 10 &= 73 & \longrightarrow 4\\ 73 : 10 &= 7 & \longrightarrow 3\\ 7 : 10 &= 0 & \longrightarrow 7\\ \end{eqnarray}$$

If we read the remainders from the bottom, we have the number 7348 - back to the original number we tried to convert to ... the same system.

If we want to describe the binary system, we do it exactly the same way - all the addends will be of the form x · 2i, where x is the digit 0 or 1. The value i again gives the orders. Just as successive division by ten gives us the number of orders in a number in the decimal system, successive division by two gives us the number of orders in the binary system.

Also note that when we divide a number by ten and ask for the remainder, the remainder will always be in the interval <0, 9>. If we divide a number by two, the remainder can be either 0 or 1.

Conversion to other systems

The previous procedure for converting from decimal to binary is so universal that it can be applied to other systems. If we want to convert the number 185 to the hexadecimal system, we just divide by 16:

$$\begin{eqnarray} 185 : 16 &= 11 &\longrightarrow 9\quad(\mbox{ remainder after division })\\ 11 : 16 &= 0 &\longrightarrow 11 \end{eqnarray}$$

The number 185 in the 16 system would have the form (11, 9). Letters are usually used instead of "digits" above 9, so 10 = A, 11 = B, 12 = C, … We can write that the number 185 has the shape B9 in the 16 system.

Similarly, we can convert the number B9 from the 16 system to the decimal system.

$$ B9_{10} = 11\cdot 16^1 + 9\cdot 16^0 = 11\cdot16+9=185 $$

Online system conversion tool