Numbers and Codes
Hexadecimal numbers
Read a hexadecimal number, turn it into decimal or into binary, and say why programmers write bits this way.
Binary is how a computer really stores a number, and it is exhausting to read: eight bits of nothing but 0s and 1s all look the same after a while, and one mistyped digit is invisible. So programmers write the same bits in hexadecimal instead. Hexadecimal counts in sixteens rather than tens, which means it needs sixteen digits — six more than we have numerals for. The first ten are the ordinary 0 to 9, and after that the letters take over and carry the count on, one letter for each of the six values that has no numeral of its own.
One digit, four bits
This is the whole reason hexadecimal is used at all. Four bits can be arranged in sixteen ways, and hexadecimal has exactly sixteen digits — so one hexadecimal digit stands for one group of four bits, always, with nothing left over and no arithmetic in between. That is why you can turn binary into hexadecimal by chopping the bits into fours from the right and writing down one digit per group, and turn it back the same way. In a number system based on ten, no such tidy swap exists at all.
Worked example
What is the hexadecimal number 6B in decimal?
Two digits, so the left-hand one counts sixteens and the right-hand one counts ones.
It is the same idea as tens and units, with sixteen in the place of ten. Every number system does this; only the size of the jump changes.
Try it together
Now go the other way together: write the decimal number 90 in hexadecimal.
Two digits will be enough. Work out the sixteens first and the leftovers second.
1.How many whole sixteens fit inside 90?
Have a go
Have a go on your own. Write the eight bits 11110011 as two hexadecimal digits.
Ready to practice?
Eight questions on what you have just read. Nothing is timed, and you can play as many times as you like.