1  Theory of Computer Science / Hexadecimal


hexadecimal Uses
Why do we use hexadecimal?
We already have the denary and the binary number systems so it may seem a little strange to introduce a third. There are many reasons why we use hexadecimal and they all boil down to the fact that a smaller hexadecimal number can be used to represent a much longer binary number.
For Example  1 hex digit e.g. A is can represent 4 bits...... a 6 digit hex code can represent 24 bits.
For Example  1 hex digit e.g. A is can represent 4 bits...... a 6 digit hex code can represent 24 bits.
 It is much easier for a human being to remember a shorter hex code than a longer sting of binary
 It is also easier for a human to spot mistakes in a shorter hex code than a longer binary number
Spot the mistake  Try it yourself
Below are two versions of the same 6 digit hex code. One is labelled correct and one is labelled incorrect. How long will it take you to spot the mistake in the incorrect code?
Correct Hexadecimal
6Afc59 
Incorrect Hexadecimal
6CFC59 
It probably didn't take you very long to spot the mistake. This is one very good reason why we use hexadecimal.
Now for comparison. How long will it take you to spot a mistake in the two binary numbers below?
Now for comparison. How long will it take you to spot a mistake in the two binary numbers below?
Correct Binary
101101010110101011010101010001110101000101010101001001001010011001011001011101010101010101000010010101010101001010101 
Incorrect Incorrect Binary
101101010110101111010101010001110101000101010101001001001010011001011001011101010101010101000010010101010101001010101 
I can imagine that the binary took you a lot longer!
Another reason why we use hexadecimal is related to screen space. Due to the fact that one hexadecimal digit is used to represent 4 binary numbers, the hex allows a number to be displayed using less physical screen space.
Practical uses of Hexadecimal
What do we use hexadecimal for?
There are a number of practical uses for the hexadecimal number system in Computer Science. These include:
HTML Colour Codes, MAC addresses, Memory Dumps or Assembly language
HTML Colour Codes
In web design it is very common for a 24bit RGB colour system to be used. This colour system requires that every useable colour is represented by a 24bit long binary number.
How does this work?
The system works by mixing shades of Red, Green and Blue to create the desired colour. Specifically, there are 256 shades of Red, 256 shades of Green and 256 shades of Blue that can be mixed together.
We know that we can make 256 different numbers with 8 bits therefore we have 8 bits for each of the three colours. 8 X 3 = 24 bits.
So as a web / graphic designer who may commonly need to use specific colours in their designs it will come down to what is easier to remember, a 24 bit long binary number OR a 6 digit Hexadecimal number?
How does this work?
The system works by mixing shades of Red, Green and Blue to create the desired colour. Specifically, there are 256 shades of Red, 256 shades of Green and 256 shades of Blue that can be mixed together.
We know that we can make 256 different numbers with 8 bits therefore we have 8 bits for each of the three colours. 8 X 3 = 24 bits.
So as a web / graphic designer who may commonly need to use specific colours in their designs it will come down to what is easier to remember, a 24 bit long binary number OR a 6 digit Hexadecimal number?
MAC Addresses
Media Access Control (MAC) addresses uniquely identify network enabled devices.
Your PC, Smart phone and all other connected devices will have a unique MAC address by which they can be identified.
Your PC, Smart phone and all other connected devices will have a unique MAC address by which they can be identified.
The MAC address is usually 48 bits long e.g.
110100101011101010100001010101111010100111010111
It is much easier for humans to deal with if this is represented by 6 Hexadecimal pairs (12 digits).6
E.g. D2:BA:A1:57:A9:D7
110100101011101010100001010101111010100111010111
It is much easier for humans to deal with if this is represented by 6 Hexadecimal pairs (12 digits).6
E.g. D2:BA:A1:57:A9:D7
Memory Dumps
A Memory Dump is the process of taking all information content in RAM and writing it to a storage drive.
Developers commonly use memory dumps to gather diagnostic information at the time of a crash to help them troubleshoot issues and learn more about the event.
Reading this information in Binary would be unmanageable and therefore the data is presented in Hexadecimal form.
Developers commonly use memory dumps to gather diagnostic information at the time of a crash to help them troubleshoot issues and learn more about the event.
Reading this information in Binary would be unmanageable and therefore the data is presented in Hexadecimal form.