Binary is a base-2 number system, which means it uses just 2 different types of digit to represent data. For example, we are used to using a base-10 system, which is called denary, using the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. Binary uses just 0 and 1.
Computers don't understand denary numbers, so they use binary instead. Binary is the language computers use to communicate and understand information. Any number can be converted into a string of 1s and 0s in order to simplify it for a computer to understand.
How binary works can be explained quite simply with a grid. In a 4-bit system, each of the digits in a binary number represents one of the following:
8 4 2 1
I find it easiest to think of 0 meaning "off" and 1 meaning "on". If we take the binary number 1001, and put it into the grid, we can easily work its value.
8 4 2 1
1 0 0 1
As you can see, the numbers 8 and 1 are switched "on" because they each have a 1 as a placeholder. Numbers 4 and 2 are switched "off" because they have 0. If we add 8 and 1 together we get 9, which means that the binary number 1001 is equal to 9.
This 4-bit system can be used to represent any number upto 15. Don't believe me? Try it yourself.
Larger Binary Strings
But what if you want to convert a number greater than 15? No problem. Binary numbers can be infinitely long, meaning that any number imaginable can be represented as a string of 0s and 1s.
As you probably noticed, the numbers we used in the grid earlier were each double that of the number to their right. If we continue to double the numbers in this way, we can make bigger numbers. For example, an 8-bit system would look like this:
128 64 32 16 8 4 2 1
Using this 8-bit system, we can represent any number upto 255. This is the largest system you'll probably have to deal with for your GCSE.
Test yourself! - Binary to Denary
Have a go at converting the following to denary. You may find it easiest to draw a grid first.
Hint: If you're struggling to work them out in your head and you don't have a calculator, try adding up the multiples of ten first. For example, 8+2=10, 16+4=20, 64+16=80, 128+32=160. Now add on everything else.
Hexadecimal is another way of representing large numbers. Hex is a base-16 system which uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F.
Converting 1-bit hex into denary is simple. The numbers 0-9 are the same, with 0=0, 1=1, 2=2 and so on. The values of the digits A-F are as follows:
A=10 B=11 C=12 D=13 E=14 F=15
Hexadecimal is most often used to simplify long binary strings so they are easier for humans to understand. This is because each digit of hex represents a chunk of 4 binary digits. Let's try converting the binary number 10011101 into hex. First, split the number into two smaller, more manageable, 4-bit chunks:
1 0 0 1 | 1 1 0 1
Take the first chunk. Using the 8421 grid we saw earlier, we can work out that 1001 in binary is equal to 9. Now take the second chunk. Using the 8421 grid again, we know that 1101 in binary is equal to 13, which in hex is D. So now we know that 10011101 in binary is equal to 9D in hex.
Hex to Denary
You probably found converting hex to binary pretty easy, right? That's why it's always a good idea when converting hex to denary, to convert the number into binary first. Let's try that.
Take the hex number 5E. 5 in 4-bit binary is 0101. The hex digit E is equal to 14, which in binary is 1110. So we know that 5E in hex is equal to 01011110 in binary.
Now we just need to convert this number into denary. You may want to draw a grid like we did before, or you could just work the answer out in your head if you prefer. Either way you should get the answer 94. So we know that 5E in hex is equal to 94 in denary.
Now you should be able to convert denary to hexadecimal too, using this method but going through it backwards, converting the number to binary first.