In a moment of boredom, I’ve cobbled together a simple game. Simple as in not flashy, as opposed to the easy kind of simple. You can find the link under the screenshot at the bottom.
It’s a small game that tasks the player with converting a number to its binary equivalent, which will probably be having you screaming “NOOOOOPE!” in a heartbeat, but seriously, if you understand basic maths, it’s not that hard. So how do you play this, you ask? Well, you’re given a number, which you must convert to binary, and to do that, you can go through the following process:
- Divide the number by two.
- If the number you’re dividing is an odd number (ending in 1, 3, 5, 7 or 9), the easiest thing to do is subtract one before dividing. The subtracted one becomes the remainder for your result.
- If the number you’re dividing is even (ending in 0, 2, 4, 6 or 8), you can just divide it and the remainder will be 0
- Write down your answer, and the remainder beside it.
- Divide that answer by two again.
- Write down your new answer below the previous one, and again, the remainder beside it.
- Continue until you finally divide one by two (yes, you need to do this).
- Now, on a new line, read from the bottom of your list and work your way upward, writing each remainder from left to right. Ideally, you should probably check it by converting it back to a whole number again, but that’s a entirely different process that I won’t go into yet.
So say you had the number, ooh, 3214 to convert. You’d divide that number by 2, write down the answer and the remainder, then divide that answer by 2 and so on, like so:
3214 / 2 = 1607 r0 1607 / 2 = 803 r1 803 / 2 = 401 r1 401 / 2 = 200 r1 200 / 2 = 100 r0 100 / 2 = 50 r0 50 / 2 = 25 r0 25 / 2 = 12 r1 12 / 2 = 6 r0 6 / 2 = 3 r0 3 / 2 = 1 r1 1 / 2 = 0 r1
And then, you make a note of all the remainders from the bottom to the very top of the list:
1 1 0 0 1 0 0 0 1 1 1 0
Make sense? No? It might eventually. This game is essentially that same process, just with a counter to track how many errors you make along the way, and it gives you a random number. So you’re probably wondering how all those ones and zeros equate to 3214, right? Well, each one represents a certain number, and those numbers start from 1 at the very right and each number after that, toward the left is double the previous one, like so:
Knowing those numbers allows you to add them together. Think of them as an array of switches, 1 being that number switched on and 0 being switched off. So let’s take our binary we just made:
Now let’s take all the numbers that are “switched on”:
+ 2048 + 1024 + 128 + 8 + 4 + 2 ------ = 3214
Ta-dah! Make any sense? Yes? No? Oh, well. You’ll find the ZIP file in the link below the screenshot. It requires Python 2.7, which you can get from the Download section of python.org if you’re running Windows or Mac OS. Linux users may have it installed already, depending on you distro, but if not, it should be available from your distro’s package manager. Full instructions (to the best of my abilities anyway) can be found in the README file in the ZIP.
For those that are even remotely interested, I stuck this up on Github too.