Conversion between hexadecimal and decimal

Data representation

In the previous lesson we showed that hexadecimal format is used whenever there is the need to represent a binary number. This is because the conversion between the two formats is very easy and, with the right training, can be performed on the fly without the need to use a calculator or a sheet of paper.

To convert an exadecimal number to binary, we just have to convert one symbol at a time, using the reference table provided in the previous lesson.

BinaryExadecimal
00000
00011
00102
00113
01004
01015
01106
01117
10008
10019
1010A
1011B
1100C
1101D
1110E
1111F

For instance, if we have to convert the hexadecimal number:

AB4F

The calculation will be carried out as shown in the following table.

AB4F
1010101101001111

The result is obviously

1010101101001111

The conversion from binary to hexadecimal works more or less in the same way. We just have to group the bits, four at a time, starting from the right. If the last group has less than four bits, it can be padded with enough zeros on the left.

Let’s convert the binary number:

10101111010001

The conversion will be carried out as in the following table. The leftmost part of the sequence: 10, is made of two bits and has been rewritten as 0010.

0010101111010001
2BD1

The result is:

2BD1