# 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.

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.