- [Craig] In this video, we're looking at the way computers store numbers using binary
and how we convert between denary, our number system, and 8-bit binary.
(uplifting piano jingle)
So, we already understand that everything in a computer system must be stored and represented in just two states,
0s and 1s, known as binary.
This includes all numbers - so, how can this work?
How do we store the number 89, for example, when we only have 0s and 1s available?
Well, let's take a step back and appreciate that humans already use a similar system known as denary.
We represent all numbers using just the numbers 0 to 9,
each digit having its own unique symbol.
Perhaps because we only have 10 digits on our hands, it makes sense to count with just 10 unique symbols.
So, what happens when we get to the number 10?
Well, as we have no more unique symbols other than 0 to 9, we say that we have a 1 and a 0,
or in other words, one 10 plus nought 1s.
one, zero - ten.
This continues, and if we think about the number 89, that is eight 10s plus nine 1s,
or to put it another way, 8 times 10 plus 9 times 1.
To store numbers above 99, we simply introduce another column.
This denary number system is known as base-10.
The binary system, known as base-2, works in a very similar way.
The only difference is there's no number above a 1.
Therefore, when we want to represent the number 2, we have no unique symbol for that,
and we have to start using a new column.
The number 3, for example, in 3 bits, would be 0-1-1.
That means we've got no 4s,
plus one 2,
plus one 1,
or 0 times 4, plus 1 times 2, plus 1 times 1, equalling 3.
So, with a binary number system, each column doubles the one before.
So, how do we convert from a denary number to a binary number?
Well, there are two methods.
Both are equally valid, and you just need to use the one you feel most comfortable with.
There is the divide-by-two method, which makes use of modulus, the remainder of a division by 2,
and the binary number line method.
Let's take a look at each method in turn.
Okay, so here's the divide-by-two method.
So, we're going to start with the number 89, and we're going to progressively divide it by 2
and work out what's remaining at each stage.
So, we start with 89, we divide by 2, which gives us 44,
and there is 1 left over, so we write a 1 in the remainder column and we continue.
44 divided by 2 is 22 with 0 left over.
22 divided by 2 is 11 with 0 left over.
11 divided by 2 is 5 with 1 left over.
5 divided by 2 is 2 with 1 left over.
2 divided by 2 is 1 with 0 left over.
And finally, 1 divided by 2 is 0 with the whole 1 left over.
To get the binary back, we now simply read the number from bottom to top.
So, the number 89 in binary is 1-0-1-1-0-0-1.
Now, quite often in the exam, you'll be asked to represent numbers in eight bits, and we only had seven here,
so you can pad any leading numbers with 0.
So, in an exam, you'd write 89 out as 0-1-0-1-1-0-0-1.
Now, the chances are, you won't use that method in an exam, so we're not going to dwell on it for too long,
but it's helpful to see nonetheless.
Instead, what you'll probably want to remember is simply to write out a binary number line, as shown here,
and consider whether the number you want to store is more than or equal to the value in the column heading.
If it is, we write a 1 and reduce the number by that amount.
So, let's see what I mean.
So, we want the number 89, and we start on the left with 128.
Well, how many 128s fit into 89?
Well, the answer is 0, so we write 0 and we've got 89 left over.
How many 64s fit into 89?
Well, 1 fits in and we've got 25 left over, so we progress to the next column.
So, how many 32s fit into 25?
Well, that's 0 with 25 left over.
How many 16s fit into 25?
Well, that's 1, and now we have 9 left over.
How many 8s fit into 9?
Well again, it's 1 with 1 left over.
4 doesn't fit into 1,
2 doesn't fit into 1,
and finally, 1 fits into 1 once with a 0 left over.
And again, you read from left to right, and you've got the binary for 89.
To convert from denary to binary, always use this number line,
and it's worth showing your working in the exam,
and it ensures you're less likely to make a silly mistake.
You can always confirm your answer by simply adding up the columns you've got 1s in.
So, we have a 64 and a 16 and an 8 and a 1 which, of course, is 89, the number we were expecting.
To convert from binary to denary, again use a number line and simply add up the values of the columns that have a 1 in.
So first, we write out our binary number - in this case, 0-1-1-0-0-1-1-0.
And now, all we need to do is add together the columns that have 1s in.
So, a 64 plus a 32 is 96, plus a 4 is 100, plus a 2 is 102.
Therefore, the number 0-1-1-0-0-1-1-0 in binary is the number 102 in denary.
Be careful when answering exam questions because they may ask you to provide your answer in a certain number of bits.
If you're asked to provide the answer in 8 bits, as mentioned earlier, you must ensure you have all 8 bits of the number in your line.
Remember, you can pad with leading 0s as you need to.
It's worth knowing that at GCSE, you're only going to be expected to convert 8-bit binary numbers.
(uplifting piano jingle)