I wrote this some time ago, you might want to read this.
Why Hex is easy
You might have come across the hexadecimal notation and thought that's complicated I don't understand it, all those numbers and letters it is hard.
Well every programmer and hardware designer uses hex for one simple reason, it is easy, far easer than the alternative. The only snag is that there is a very small learning curve, so small in fact that I like to think of it as a learning bump. I would like to explore what that is and why you should use it.
When we teach children to multiply say three times four, often to get them started we say write down a group of four marks. Then repeat that group three times and finally add up all the marks on the paper to get the answer.
That is supposed to get them the basic idea, but as a long term strategy it is a dead end. If you are not careful this becomes their only strategy for multiplication and I have seen 14 year olds multiply six by ten by covering the paper with marks. In this case all that is needed is a simple application of multiplication tables. Bear this in mind as we consider hex.
Now inside every computer information is stored as a collection of binary bits, that is a collection that we can represent by writing down a list of zeros and ones to represent each state. Inside the computer it is not a sequence of zeros and ones, it is in fact a system of switches where each switch can be open or closed.
To make life easer when designing a computer we arrange these individual bits into groups of eight and call these groups a byte. So each byte consists of eight bits, but what do they mean?
Well they can mean absolutely anything we want them to mean, depending on the context we find them we can interpret the bytes as numbers, text, computer instructions or patterns of lights to turn on. To the computer they are all the same, just a collection of bits. That is an important thing to remember, all a computer does is manipulate bits, it is us that put a construct on those bits.
However what ever they represent we have to have some way of representing them and the simplest is by writing down the string of zeros and ones, so a specific byte might be represented by say 00110010.
Now I don't know about you but that is a bit of a difficult thing to cope with, for a start it is a long sequence and there is very little encoding going on. That is each place in that representation can only be one of two things. That is great if you are a computer but that is not how the human mind works best. We work best when there is some chunking going on, that is to express the sequence with a shorter length but more variability of what can be in each place.
the obvious solution would be to turn that sequence into a decimal number by having each bit represent a power of two. So starting at the right hand side we have the first bit or bit zero as we call it represent two to the power of zero or one.
So if the right hand most bit is a one then that contributes a one to the whole number. We can then move to the left and the second bit represents two to the power of one, or two, and so on down the list. ending up with the left hand most bit representing two to the power of seven or 128. Then we add up all the bits in that byte that have a one in them according to their place value to get the final number of 146. This is then a decimal representation of that bit pattern. so do we have it cracked? I think not it requires quite a bit of mental gymnastics and the reverse operation, getting from the decimal representation to a bit pattern is definitely a pencil and paper job.
But we are half way there to making it easy. Let's consider breaking the byte into two, that is two groups of four bits. A group of four bits is rather amusingly called a nibble, not quite a byte. In binary this already looks much simpler we would write 0110 0011.
I don't know about you but that space in the middle makes it so much easer to keep your place. Now suppose we take each of those groups and apply the same decimal conversion to that as we did to the previous byte we get the number 63.
That is fine and easy to remember and you can do it quite simply in your head, there are only four add ups to do and they are only 8 + 4 + 2 + 1 at the worst. In fact the first group was 4 + 2 = 6 and the second 2 + 1 = 3. Great that was easy.
But hang on, what happens when we have a result that is more than 9 in a group. Suppose we had 0000 1010, that would give us zero for the first group and 10 for the second. so the number we would have would be 010, we wouldn't know if this was a three nibble number 0000 0001 0000 or a two nibble number 0000 1010.
To get round this problem we don't use numbers to represent values greater than nine we use letters. So if we get to a value of ten when we add up our nibble we call it A or a.
if we get eleven we call it B and so on up the alphabet until fifteen which is F. In that way we can stick to one position in our number representing four bits or a nibble. We have shortened the sequences length and chunked up to a good degree.