Skip main navigation

Converting Numbers to Binary

Introduce the base 2 numbering system known as binary, and show how to convert our everyday base 10 numbers (denary) into binary and vice versa.

In this step we will introduce the base 2 numbering system known as binary, and show how to convert our everyday base 0 numbers (denary) into binary and vice versa.

Binary and denary

Our usual everyday number system is sometimes called ‘denary’. When we count in denary we begin at 0, count all the way up to 9, then go back to 0 again, but have an additional digit in the next column. You could ask yourself, why is it that we have ten separate symbols to represent all our numbers? The answer is most probably because we have ten fingers and thumbs, although it’s not really known.

However, computers use binary, in which we only have two digits available to us, 1 and 0. So, after we count up to 1 we go back to 0 again, but have an additional digit in the next column. A binary digit is commonly known as a bit.

Binary is called base 2 because there are two digits (bits) available with which to count: 0 and 1. The term base 2 also refers to the fact that each binary place is two times bigger than the previous one. Our everday counting, denary, is described as base 10, as we have ten digits available: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

So how can we convert from one to the other? When you were learning about numbers as a child, you probably used the terms thousand, hundreds, tens, and units (or ones). These are all powers of 10. You can draw a table using all these values as headings.

10⁰ = 1

10¹ = 10

10² = 100

10³ = 1000

10⁴ = 10000

Using these headings you can write in a number, say 09032. Make sure that you use all of the columns that you have digits for, starting at the right-most column, which represents units. In this case 09032 has five digits, so you start filling the table from the right, beginning with the 2 in the units column:

Ten thousands Thousands Hundreds Tens Units
10000 1000 100 10 1
0 9 0 3 2

We can see that it is made up of zero 10000s, nine 1000s, zero 100s, three 10s, and two 1s.

In binary, we can do the same thing, but using powers of 2:

2⁰ = 1

2¹ = 2

2² = 4

2³ = 8

2⁴ = 16

Again, a table can be drawn up using these numbers as headings.

2⁴ = 16 2³ = 8 2² = 4 2¹ = 2 2⁰ = 1
1 0 1 1 1

As we did with denary, we can write in a binary number, such as 10111. Again, we have to make sure that we use the units (2⁰) column, with no gaps. Now we can see that the number represented in binary as 10111 is made up of one 16, zero 8s, one 4, one 2, and one 1. So, in denary, we have 16 + 4 + 2 + 1 = 23.

Try converting the following binary numbers into denary. Share your answers and any problems you have in the comments section below:

  • 1010
  • 1001
  • 10001

Converting numbers back the other way isn’t much more difficult.

If we wanted to convert the denary number 21 into binary, we could start out with an empty table like this:

16 8 4 2 1
         

We need to look in each of the columns to see what needs to be placed there using only ones and zeros. It’s easiest to do this by starting from the left: in this case we would consider the number 21 and look at the table to see which of the columns has the biggest number that is less than 21. This is 16, so our first 1 would be in the 16 column.

Step 1, running total = 16

16 8 4 2 1
1        

Now, we still have 5 left (21 – 16 = 5) so we look to the right of the 16 column. The next column along has an 8 in, which is too big to add on to our 16 and would take us to 24. This means that we put a 0 in the 8 column and look at the next column along. The next column is the 4 column which is useful (as it is less than 5) and gets us closer to our target or 21, so we put a 1 in the 4 column.

Step 2, running total = 20

16 8 4 2 1
1 0 1    

At this stage we have 16 + 4 = 20. We still need 1 to get to 21, so we put a 0 in the 2 column and a 1 in the 1 column. Now we have arrived at 21 and have (1×16) + (0×8) + (1×4) + (0×2) + (1×1) = 21. This is shown in the table below:

Step 3, final total = 21

16 8 4 2 1
1 0 1 0 1

Reading off from the table, we can see that 21 in binary is 10101.

Have a go at converting the following denary numbers into binary:

  • 31
  • 12
  • 64

Don’t forget to share your answers and help each other out in the comments section. Also, describe how you think the binary table may have to be modified if you wanted to represent a binary number with more than 5 bits, for example 101010?

This article is from the free online

Understanding Maths and Logic in Computer Science

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now