Converting Between Hexadecimal & Binary.

The previous page illustrated how to convert binary numbers to decimal, by adding together the bit weightings of any bits in the number that are one. Using the same technique, it is very easy to work out all of the binary equivalents for each hexadecimal digit (and vice versa). This is because it only requires four bits to represent all of the hexadecimal digits. Therefore, it only requires the addition of up to four numbers, selected from the possible values of 8, 4, 2 & 1.

e.g. A (which is ten in decimal) is obtained from the addition of 8 and 2 from the numbers available.
Therefore from the numbers available (8, 4, 2 & 1) we need One 8, Zero 4s, One 2 and Zero 1s. Therefore A hex = 1010 binary.

The table below shows the binary numbers for each hexadecimal digit.

Hex Bin Hex Bin
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111

From above, you can see that there are exactly 16 different possible combinations of ones and zeros, using four bits. This matches with the sixteen different hexadecimal digits.(0- F).

Because of this match, then given any length of binary number, if we arrange the bits into groups of four (starting from the l.s.b.), we can just replace each group, with its corresponding hexadecimal digit, to convert the number from binary to hexadecimal.

Hexadecimal to Binary.

Example.
1011001101 .
Arrange into groups of 4 bits.
0010 1100 1101, (note we add leading zeros to the left hand group for more consistent presentation).
From the table above this gives 2 C D hexadecimal.

Binary to Hexadecimal.

To convert from hexadecimal to binary is just as simple, we simply replace each hexadecimal digit, with the corresponding four bit binary number.

Example.
4EA2.
0100 1110 1010 0010 .

Due to this correspondence between groups of four bits and hexadecimal digits, binary numbers are often written with groups of four bits. Leading zeros are then inserted, when needed, into the most significant group, to maintain the four bit grouping pattern

(i.e. 1011101100, is often written as 0101 1100 1100, rather than 101 1100 1100 )