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 is equal to 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 manner.
Additionally, each hexadecimal digit represents four bits (also called a nibble) in the binary system. Therefore, the 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:
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.
We group into groups of 4 digits:
0001 0110 1011 0100We convert each group:
0001converts to10110converts to61011converts toB0100converts to4
We combine the obtained hexadecimal values:
16B4
Thus, 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.
- We convert each hexadecimal digit into 4 bits using the previous conversion table.
Example of hexadecimal to binary conversion
We will convert the hexadecimal number 2A7 to binary.
We look for the equivalents of each hexadecimal digit to a block of 4 bits
2is0010Ais10107is0111
We combine the 4-bit blocks,
0010 1010 0111
Therefore, 2A7 in hexadecimal is equal to 001010100111 in binary.
