Skip to 0 minutes and 1 secondIn this step, we're going to look at working with binary. As you saw in a previous step, a Turing machine is capable of operating using only two symbols, 1 and 0. And the rather bold statement was made that using just these symbols, any solvable problem could be solved. How can this be? How can you even add two numbers, say 12 and 6, if you only have the ability to use ones and zeros? To answer this question, we should take a brief look at the nature of numbers. When you were learning to do basic arithmetic when you were a child, you probably learned about counting in ones, tens, hundreds, and thousands. This is called base 10, or denary.

Skip to 0 minutes and 45 secondsWhen writing down numbers, you 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 10 separate symbols to represent all our numbers? Why not five? Then counting would look like this. The answer is most probably because we have 10 fingers and thumbs, although it's not really known. Some cultures around the world count in different bases, and most people are fairly happy using base 12 and base 60 when telling the time. The Turing machine uses base 2, or what is often called binary. Here's an example of counting in binary.

Skip to 1 minute and 31 secondsYou might recall that this is exactly what your Turing machine did in the last step. So to answer the original question, how could a Turing machine add the numbers 12 and 6, the answer is that the machine would use binary representations of these numbers. Here's an example of simultaneously counting in both binary and denary. So how can we convert from one to the other? We said earlier that when you were learning about numbers as a child, you probably used the terms ones, tens, hundreds, and thousands. These are all powers of 10. You can draw a table using all these values as headings.

Skip to 2 minutes and 12 secondsYou can write in a number, in this case 09032, and we can see that it is made up of zero 10,000s, nine 1,000s zero 100s, three 10s, and two 1s. In binary, we can do the same thing, but using powers of 2.

Skip to 2 minutes and 35 secondsAgain, a table can be drawn up using these numbers as headings.

Skip to 2 minutes and 40 secondsAs we did with denary, we can write in a binary number, such as 10111. Now we can see it is made up of one 16, zero 8s, one 4, one 2, and one 1. So if this was in denary, it would be the number 23. You're now going to have a go at doing some binary to denary conversions yourself. So you might like to replay this video and have a look over it again. Pause the video here and have a practise on the following binary numbers, and see if you can work out what they would be in denary. There'll be a quiz on this in the next section. Converting numbers back the other way isn't much more difficult.

Skip to 3 minutes and 23 secondsIf we wanted to convert the number 21 into binary, we could start out with an empty table like this. Then look in each of the columns to see what needs to be placed there using only ones and zeros. In this case, we would need one 16, zero 8s, one 4, zero 2s, and one 1.

Skip to 3 minutes and 54 secondsReading off from the table, we can see that 21 in binary is 10101. Have a go with converting the following denary numbers into binary. Don't forget to share your answers and help each other out in the comments section.

Working with binary

In this step we’re going to look at working with binary.

As you saw in a previous step, a Turing machine is capable of operating using only two symbols – 1 and 0 – and the rather bold statement was made that, using just these symbols, it can do any computation!

How can this be? How can you even add up two numbers, say 12 and 6, if you only have the ability to use 1s and 0s?

To answer this question, we should first take a brief look at the nature of numbers. When you were learning to do basic arithmetic, when you were a child, you probably learned about counting in ones, tens, hundreds and thousands.

This is called base 10. When writing down numbers, you begin at 0, count up to 9, then go back to 0 again, but add an additional digit in the next column.

Animated GIF showing numbers counting up in denary

You could ask yourself, why is it we have 10 separate symbols to represent all our numbers? Why not 5? Then counting would look like this:

Animated GIF showing numbers counting up in base 5. This means that after the number 04, the next number is 10, and after 14 the next number is 20.

The answer is most probably because we have 10 fingers and thumbs, although it’s not really known. Some cultures around the world count in different bases, and most people in the world are fairly happy using base 12 and base 60 when telling the time.

The Turing machine uses base 2, or what is often called binary. Here’s an example of counting in binary

Animated GIF showing binary numbers counting up, from 0 to 1 to 10 to 11 to 100 to 101 to 110 to 111 to 1000 and so on.

You might recall that this is exactly what your Turing machine did in the last step.

So to answer the original question – how could a Turing machine add the numbers 12 and 6? – the answer is that the machine would use the binary representations of these numbers.

Converting binary to denary

Here’s an example of simultaneously counting in both binary and denary. Animated GIF showing numbers counting up simultnaeously in both binary and denary.

So how can we convert from one to another?

We said earlier that when you were learning about numbers as a child, you probably used the terms ones, tens, hundreds, thousands. These are all powers of 10.

graphic showing the powers of ten, 10 to the 0 equals 1, 10 to the 1 equals 10, 10 to the 2 equals 100, etc

We can then arrange these values horizontally to be used as headings.

The powers of ten laid out horizontally from right to left

Now we can write in a number – in this case 09032 – and we can see that it is made up of 0 x 10000, 9 x 1000, 0 x 100, 3 x 10 and 2 x 1:

the powers of ten and beneath them the denary digits 0 9 0 3 2

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

graphic showing the powers of 2. 2 to the 0 equals 1, 2 to the 1 equals 2, 2 to the 2 equals 4 etc.

Again, a the values are arranged as headings.

powers of two laid out horizontally from right to left

As we did with denary, we can write in a binary number such as 10111.

powers of two with the binary values 1 0 1 1 1 beneath them

Now we can see it is made up of 1 x 16, 0 x 8, 1 x 4, 1 x 2 and 1 x 1. So if this was in denary it would be the number 23.

Animated graphic showing how the binary values can be multiplied by the powers of two as above to calculate the denary value.

Have a practice on the following binary numbers and see if you can work out what they would be in denary. There’ll be a quiz on this in the next section.

1010
1001
10001

Converting numbers back the other way isn’t much more difficult. If we wanted to convert the number 21 into binary we would do it like this:

Animated graphic showing how the denary number can be divided by the powers of two, with the remainder used for the next division, to turn a denary number into a binary number

We keep dividing the number by a power of two, and then using the remainder for the next division.

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.

7
15
40

You can compare your answers in the comments section, or even challenge each other to do more binary to denary and denary to binary calculations.

Share this video:

This video is from the free online course:

How Computers Work: Demystifying Computation

Raspberry Pi Foundation