- [Craig] In this video, we take a look at how you convert between denary and two-digit hexadecimal.
If you haven't already watched the video on converting between denary and 8-bit binary,
I strongly suggest you watch that video first and then come back here.
(uplifting piano jingle)
So, we've already learned that the denary system is a base-10 system.
We only have the symbols 0 to 9 and when we want a 10, it's a 1 and a 0.
We've also learned that the binary system is a base-2 system, so we only have the numbers 0 and 1.
And if we want a 2, it's 1 and 0.
And now, we're introducing hexadecimal, which is a base-16 number system,
and it means we've got the numbers 0 through 15, and if you want a 16, it's a 1 and a 0.
Now, hexadecimal gives us a unique problem.
Because we have no symbol for the numbers 10, 11, 12, 13, 14 and 15,
because of course, in denary, they are represented by combining our symbols 0 to 9,
we therefore have to create a symbol to represent these additional numbers.
Now, just for convenience, we use the letters of the alphabet.
So, A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15,
and remember that 16 would be 1-0.
So, computers don't really use hexadecimal,
but because of the close relationship between hexadecimal and a binary nibble,
they become really useful for representing large binary numbers in a smaller number of digits,
and they're used in computer science to represent colours, memory addresses, MAC addresses and much, much more.
So, just spend a few moments exploring this table,
and you'll see what I mean by the close relationship between binary nibbles and hexadecimal.
With hexadecimal, there are 16 numbers, 16 possible permutations from 0 to 15,
and we can represent the numbers 0 to 15 in binary using 4 bits,
from 0-0-0-0 through to 1-1-1-1.
So, let's have a look at converting the denary number 12 into hexadecimal.
Now, what you want to do is go through binary - it just makes things a lot easier.
So, we take the number 12 and we write it out in its binary, which we showed you in a previous video.
So, there's the number 12 in binary, 0-0-0-0 and an 8 plus a 4 - 8 plus 4 is 12, and then 0 and 0 at the end.
Now, to convert this number into hex, we group our binary timeline into nibbles - so, that's groups of four.
So, we have four 0s here - well, 0 is obviously 0, we don't actually need this number here,
but we're showing it for completeness.
And now, we group the next nibble or group of four.
We have a 1 in the 8 column and a 1 in the 4 column, so that's 8, 9, 10, 11, 12,
and remember that 12 in hex is C.
So, the denary number 12 in hex is 0C, or more simply put, just C.
Okay, let's look at the number 24 - so first, we're going to write it out in binary.
So, there's number 24, it's a 16 plus an 8.
We're going to start with our left-hand nibble,
and notice we've got our own mini binary weighting line of 1, 2, 4 and 8.
We're not using the 16, 32, 64 and 128.
And we have a 1 in the 1 column, so we place 1 down the bottom there.
We then take the next nibble and again, we have a 1 in the 8 column, so we have 8.
So, the denary number 24 in hexadecimal is 1-8.
Now, that's important - it's not eighteen, it's 1-8,
and it's important to note here that although hexadecimal has letters available to it,
not every denary number will convert into a hexadecimal number that contains letters.
So, let's look at a large number now, 230 - the process is exactly the same.
First of all, let's write out the binary.
So, there's the number 230 written out in binary and we're going to start with the left-hand group of 4 bits, the first nibble.
So, we have a 1 in the 8 column plus a 1 in the 4 column, plus a 1 in the 2 column - so, that 8, 9, 10, 11, 12, 13, 14.
And of course, in hexadecimal, 14 is E, so the left nibble represents E.
Then the right nibble, we have a 4 plus a 2, which is 6 - and in hex, that is simply 6.
So, 230 in denary is E6 in hexadecimal.
Let's do one last one now of 100, and again,
why don't you pause the video here, work through this one yourself and then unpause the video and see if you get the same answer we do?
So, first of all, there's 100 written out in binary - now, let's start with the left-hand nibble first.
So, we have a 1 in the 4 column and a 1 in the 2 column,
remembering again, we're using the mini binary weighting line for the nibble,
not the field weightings at the top, so we've got a 4 and a 2 is 6.
And then the right-hand nibble, we just have a 1 in the 4 column, so that's 4.
So, the denary number 100 in hex is 6-4.
Again remember, that's 6-4, not sixty-four.
So, what about if you get asked to go the other way?
If you get given a hexadecimal number and you're asked to put it into binary or denary?
Well again, if you get told to put it into denary, just work through binary first.
So, it's quite a straightforward process - let's take a look.
So, we'll start with the left-hand hexadecimal digit first, which is an A,
and we know that needs to turn into one nibble, so A needs to turn into 4 bits.
Well, A represents 10, so that's an 8 and a 2, so we've got a 1 in the 8 column followed by a 0,
followed by a 1 in the 2 column followed by a 0, 8 and 2 is 10 - or A in hex.
We do exactly the same thing with B - the hexadecimal digit B needs to turn into 4 bits or a nibble.
B in hex is 11, so we want an 8, zero 4s and a 2 and a 1 - 8, 9, 10, 11.
So now, we have our binary equivalent of the hexadecimal digit AB,
and that's 1-0-1-0-1-0-1-1.
To convert that into denary, we now just add up the original binary weighting lines if the columns have a 1 in.
So, we have 128 plus a 32 plus an 8 plus a 2 plus a 1 is 171.
So, the base-16 hex number AB is 171 in denary.
Let's do one more.
Let's convert the hexadecimal digit 3-6 - that's 3-6, not thirty-six - into binary and denary.
Again, pause the video, take it through binary and then unpause and see if you got the same answer that we did.
So, you can see we've taken the 3 and we've written that out there as a 1 in the 2 column and a 1 in the 1 column.
On the right-hand-side nibble, we've got 6, so that's a 1 in the 4 column and a 1 in the 2 column.
We add the columns together that have 1s in, 32 plus 16 plus 4 plus 2 equals 54.
Let's do one final example - we've got 7F.
Again, pause the video and see if you can work through this one without our help and then unpause it and see if you got it right.
So, the left nibble is 7, so that's 4, 2 and 1,
4, 5, 6, 7 - so, there's 1 in each of those columns and a 0 in the 8.
And the right-hand nibble is a capital F, so that is 15.
So, that's all the 1s - that's an 8, 9, 10, 11, 12, that's a 4.
13, 14 - that's a 2.
and 1 for 15.
We add together all the columns with 1s in and we end up with 127.
(uplifting piano jingle)