Hexadecimal

You should now know that binary is a base 2 number system which uses 0s and 1s to represent digits. Hexadecimal is another number system used in computing. This one has 16 different numbers, 0 to F. Below is a table which shows how hexadecimal numbers compare to the denary ones we use in every day counting.

The numbers on the top represent the numbers we use in every day life. The numbers on the bottom are the hexadecimal number system. As you can see, up to 9 they are exactly the same. Therefore 8 in denary is 8 in hexadecimal. However, instead of 10, hexadecimal uses A. After F, just like in denary, we start over again, going back to 0 and adding a new number to the left like so:

E, F, 10, 11, 12

It's a bit diffiult to get your head around at first. The number 12 there isn't the same as the number 12 you use in every day life. It may look the same, but in denary it represents the numer 18.

So why bother complicating things like this? Well, we use hexadecimal in computing because it's easier to convert to binary. Remember how we said that computers only understand 0s and 1s - that means that we have to speak to them using binary. However, since binary numbers are so long, it can get complicated for a human to use them when programming a computer. Hexadecimal is easier to understand and enter in to a system, since there are more numbers to use so they are smaller. For example, 10101111 is just AF. Since computers can't understand hexadecimal, we get a piece of software to convert it to binary for us. It's like having someone translate the words you say in to another language so you can speak to someone from a different country. You are probably thinking "well why not just use denary and translate that?" The reason we use hexadecimal is that it's much easier for us to translate in to binary, since it is a base 16 number system and we work with 8 bits at a time in binary.

CONVERTING DENARY TO HEXADECIMAL

If you are working with very small numbers up to 15, you can just use the chart (which you will need to remember but it's not that difficult) to convert denary to hexadecimal. If you are using larger numbers, here is how you do it:

STEP 1: Create a table with two columns, one called RESULT and one called REMAINDER

RESULT REMAINDER (in hex)
   

STEP 2: Take your numer and divide it by 16 (here we will use the number 43)

STEP 3: Put the answer in the RESULT column and the remainder in the REMAINDER column. Multiply the remainder by 16

RESULT REMAINDER (in hex)
2 0.6875 * 16 = 11

STEP 4: Keep dividing the whole number by 16 and multiplying the remainder by 16 until the whole number becomes 0. As you can see, this happened with our example aftetr only the second division

RESULT REMAINDER (in hex)
2 0.6875 * 16 = 11
0 0.125 * 16 = 2

STEP 5: We now get our hexadecimal number from the remainder column, by reading from bottom to top. In our example, we therefore have 2 11. Finally we convert any all the numbers in to hexadecimal so 2 stays as 2 and 11 becomes B.

43 in hexadecimal therefore, is 2B

CONVERTING HEXADECIMAL TO DENARY

To convert the other way, take your hexadecimal number and separate it in to individual digits. We will use 2B to show that it works the same the other way around.

2 B

STEP 1: Convert all numbers in to denary. Therefore, 2 stays as 2 and B becomes 11

2 11

STEP 2: Because hexadecimal is a base-16 number system, we then have to multiply each number by 16 to the power of its position. The number on the right hand side is always in the 0 position and the number to the left of that is in the 1 position. We therefore write them out like this

(2*161) (11*160)

STEP 3: If we had another digit to the left of the 2, we would just use power 2, then power 3 and so on. Finally add these together

(2*161) + (11*160)

2 multiplied by 16 to the power of 1 is 32

11 multiplied by 16 to the power of 0 is 11 (remember, anything to the power of zero just becomes 1)

Therefore, the answer is 43

1) Give two uses for the hexadecimal number system in computing

2) Why is the hexadecimal number system often used in computer programming?