The hexadecimal system is an extension of the decimal system that uses sixteen digits, 0 to 9 and A to F.
For example, the hexadecimal number 2F represents (2 * 16^1) + (F * 16^0) (which equals 47 in decimal).
The advantage of the hexadecimal system is that it provides a very compact representation. For this reason, it is widely used in programming to represent binary values in a concise and easily readable way.
Furthermore, each hexadecimal digit represents four bits (also called a nibble) in the binary system. Therefore, conversion from hexadecimal to binary is very, very simple.
Conversion between Binary and Hexadecimal
To convert a binary number to hexadecimal we do the following:
- Divide the binary number into groups of 4 digits, starting from the right.
- If the last group does not have 4 digits, add zeros to the left to complete 4 digits.
- Convert each group of 4 binary digits into its hexadecimal equivalent.
Here is the conversion table:
| Binary (4 bits) | Hexadecimal |
|---|---|
| 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 |
Example of Binary to Hexadecimal Conversion
We will convert the binary number 101101011010 to hexadecimal.
Group into 4-digit groups:
0001 0110 1011 0100Convert each group:
0001becomes10110becomes61011becomesB0100becomes4
Combine the obtained hexadecimal values:
16B4
Therefore, 101101011010 in binary is equal to 16B4 in hexadecimal.
Conversion from Hexadecimal to Binary
Converting a hexadecimal number to binary is not much more difficult. We simply do the reverse process.
- Convert each hexadecimal digit into 4 bits using the conversion table above.
Example of Hexadecimal to Binary Conversion
We will convert the hexadecimal number 2A7 to binary.
Find the 4-bit block equivalent for each hexadecimal digit
2is0010Ais10107is0111
Combine the 4-bit blocks,
0010 1010 0111
Thus, 2A7 in hexadecimal is equal to 001010100111 in binary.
