Saturday, 6 April 2013

Binary in a Scratch maths trick

Prepare to be amazed! Here is a great maths trick where we pick any number from 1 to 31 and the computer tells us the exact number we picked!

It turns out that this is a great way of taking what could be a difficult theory lesson on binary and turning it into something much more practical and interesting. In Scratch, pupils start by inputting code relating to the 5 numbered cards shown below:



When inputting the code and working through the accompanying worksheets, we notice that the numbers on the Fridge Magnets card (all the odd numbers 1, 3, 5, 7, to 31) all have a 1 in the ones place in the binary column. The numbers with a 1 in the twos place all appear on the Road Signs card. And the numbers with a 1 in the fours place appear on the Birthday Badges card. And so on.

There are patterns in how the 1s are spread out in each column. In the ones column they alternate 1, 0, 1, 0, 1, 0, . . . In the twos column the pattern is 1, 1, 0, 0, 1, 1, 0, 0, and so on. There are patterns in all the columns.

The trick works by effectively converting your decimal number in binary and then convering it back into decimal.

Let's say the decimal number 15 is selected. By telling us which of the 5 cards the number appears on we convert 15 into its binary equivalent (01111) We then convert it back into decimal by adding the binary column headers - in this case:
8 + 4 + 2 + 1 = 15.

Supporting Scratch files can be downloaded from the Computing at School website.

Open the worksheet in Google docs