Moving between Base 10, Base 2, and Base 16 can get confusing, but all three can be used when discussing computers.
Denary (Decimal)
As a child in the UK, we are taught the Base 10 system of digits, i.e. 0 through 9, known as denary. The position of the digit increments the value by a factor of 10. So:
0001 is one (1 X 1)
0010 is ten (10 x 1)
0100 is one hundred (10 X 10 X 1)
1000 is one thousand (10 X 10 X 10 X 1)
The 1 can be replaced by any digit in the range 0 through 9. So:
0009 is nine (1 X 9)
0090 is ninety (10 X 9)
0900 is nine hundred (10 X 10 X 9)
9000 is nine thousand (10 X 10 X 10 X 9)
Binary
Then when learning about computers we are introduced to the Base 2 system of digits i.e. 0 and 1, known as Binary. The position of the digit increments the value by a factor of 2. So:
0001 is one (1 x 1)
0010 is two (2 X 1)
0100 is four (2 X 2 X 1)
1000 is eight (2 X 2 X 2 X 1)
As the Binary system only has 2 digits only 1 or 0 can be used.
Hexadecimal
Hexadecimal is a Base 16 system. Hexadecimal uses the digits 0 through 9, and the letters A through F. The position of the digit increments the value by a factor of 16. So:
0001 is one (1 X 1)
0010 is sixteen (16 X 1)
0100 is two hundred and fifty-six (16 X 16 X 1)
1000 is four thousand and ninety-six (16 X 16 X 16 X 1)
The 1 can be replaced by any digit in the range 0 through F, which can be a little strange for those use to Base 10 (Denary). So, remembering that F (Hexadecimal) is 15 in the denary system:
000F is fifteen (1 X F)
00F0 is two hundred and forty (16 X F X 1)
0F00 is three thousand, eight hundred and forty (16 X 16 x F X 1)
F000 is sixty one thousand, four hundred and forty (16 X 16 X 16 X F X 1)
Comparison Table
The below table shows what the values of zero (0) through fifteen (15) look like in Base 2, Base 10 and Base 16.
Base 2 | Base 10 | Base 16 |
0000 | 0 | 0 |
0001 | 1 | 1 |
0010 | 2 | 2 |
0011 | 3 | 3 |
0100 | 4 | 4 |
0101 | 5 | 5 |
0110 | 6 | 6 |
0111 | 7 | 7 |
1000 | 8 | 8 |
1001 | 9 | 9 |
1010 | 10 | A |
1011 | 11 | B |
1100 | 12 | C |
1101 | 13 | D |
1110 | 14 | E |
1111 | 15 | F |
Bits, Nibbles, Bytes VS Hexadecimal
When working with Binary (Base 2) the individual digits are called bits, and used on their own a bit is a very small value (0 or 1). So most people use bits in groups of 4, called a nibble. The comparison table above is using nibbles in the Base 2 column. To help visualise a nibble here is the number 15:
Power of 2 | 8 | 4 | 2 | 1 |
Binary Digit | 1 | 1 | 1 | 1 |
The maximum value from a nibble is 15.
To work with greater values a byte is used which is 8 bits. The value 15 would look like this:
Power of 2 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary Digit | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
But the byte can be used for a much higher value, 255.
Power of 2 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary Digit | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Where Binary (Base 2) takes a nibble (4 bits) to represent the value of 15, Hexadecimal can do it in one digit (F). This allows for bigger numbers to be represented using less digits.
Converting Hexadecimal
To convert a binary byte to hexadecimal, split the byte into two nibbles and then each nibble into one hexadecimal digit. So one byte (8 bits) is 2 hexadecimal digits. For example, using the 255 above.
255 in Binary is 11111111:
Power of 2 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Base 2 Unit | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Splitting the byte into 2 nibbles gives us:
Nibble 1
Power of 2 | 8 | 4 | 2 | 1 |
Binary Digit | 1 | 1 | 1 | 1 |
Nibble 2
Power of 2 | 8 | 4 | 2 | 1 |
Binary Digit | 1 | 1 | 1 | 1 |
Then each nibble can be converted to Hexadecimal:
Nibble 1 represents 15 (8 + 4 + 2 + 1). 15 is F in Hexadecimal.
Nibble 2 represents 15 (8 + 4 + 2 + 1). 15 is F in Hexadecimal.
So 255 (Base 10 / Denary) is represented as 11111111 (Base 2 / Binary) or as FF (Base 16 / Hexadecimal).
What about another number, say 72 (Base 10/ Denary).
In binary this would be 01001000 (Base 2 / Binary) :
Power of 2 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary Digit | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
That binary byte can then be split into two nibbles:
Nibble 1
Power of 2 | 8 | 4 | 2 | 1 |
Binary Digit | 0 | 1 | 0 | 0 |
Nibble 2
Power of 2 | 8 | 4 | 2 | 1 |
Binary Digit | 1 | 0 | 0 | 0 |
Each nibble can then be converted in Hexadecimal (Base 16):
Nibble 1 represents 4 which is also 4 in Hexadecimal.
Nibble 2 represents 8 which is also 8 in Hexadecimal.
So 72 (Base 10 / Denary) is 01001000 (Base 2 / Binary) or 48 (Base 16 / Hexadecimal).
Base 10 (Denary) to Base 16 (Hexadecimal)
If the Base 10 (Denary) is less than sixteen (16) then it’s the same in Base 16 (Hexadecimal). For example eleven in Base 10 is 11, and in Base 16 is 11. Easy
However, once Base 10 gets to 16 and above then division gets involved. Take the Base 10 number and divide it by 16, then do the same for the remainders.
For example, 296 (Base 10).
296 / 16 = 18 with a remainder of 8
18 / 16 = 1 with a remainder of 2
1 / 16 = 0 with a remainder of 1
The Hexadecimal representation of 296 (Base 10) is 128 (Base 16).
Power of 16 | 65536 | 4096 | 256 | 16 | 1 |
Hex Digit | 1 | 2 | 8 |
This says:
( 1 X 256 ) + ( 16 X 2 ) + ( 1 X 8)
256 + 32 + 8
256