# Conversion between hexadecimal and decimal

What you should know:

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.

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

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

AB4F

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

 A B 4 F 1010 1011 0100 1111

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.

 0010 1011 1101 0001 2 B D 1

The result is:

2BD1