The binary and hexadecimal system are two major numbering systems used by computers. While it's easy to deal with small numbers in the binary format, the same cannot be said about large number manipulations. For simplification, binary digits are converted into hexadecimal numbers, and the reverse is also possible.
In order to convert binary numbers into hexadecimal ones, and vice versa, it is crucial to understand a few basics regarding the methodology. Thus, in the following sections, the conversion methods have been explained with the help of examples. Have a look at the reference conversion chart given below before proceeding.
Correlation Charts for Binary and Hexadecimal Conversions
Binary numbers represent any number (decimal or hexadecimal) using digits
0 and
1 only. Each digit '1' in a binary number represents a power of two, and each '0' represents zero. The method used to form the conversion table is explained below:
0001 = 2
0 = 1
16
0010 = 2
1 = 2
16
0100 = 2
2 = 4
16
1000 = 2
3 = 8
16
If the digit '1' occurs more than once, then you need to add the powers of 2:
0101 = 0 + 2
2 + 0 + 2
0 = 4 + 1 = 5
10 = 5
16
1010 = 2
3 + 0 + 2
1 + 0 = 8 + 2 = 10
10 = 10
16
0111 = 0 + 2
2 + 2
1 + 2
0 = 4 + 2 + 1 = 7
10 = 7
16
1111 = 2
3 + 2
2 + 2
1 + 2
0 = 8 + 4 + 2 + 1 = 15
10 = F
16
Number Chart
Binary |
Hexadecimal |
0000 |
0 |
0001 |
1 |
0010 |
2 |
0011 |
3 |
0100 |
4 |
0101 |
5 |
0110 |
6 |
0111 |
7 |
1000 |
8 |
1001 |
9 |
Alphabet Chart
Binary |
Hexadecimal |
1010 |
A |
1011 |
B |
1100 |
C |
1101 |
D |
1110 |
E |
1111 |
F |
How to Convert Binary to Hexadecimal
Step 1
Divide the binary number into sets of 4 digits starting from right to left. For example, the binary number '1001101100100101' should be partitioned as follows,
1001
|1011
|0010
|0101
➩1001 1011 0010 0101
Add leading zeroes wherever required. For example, the binary number '111011001' should be noted down as,
000111011001
Follow the same aforementioned partitioning step,
0001
|1101
|1001
➩0001 1101 1001
Step 2
Refer to the aforementioned chart, and write down the hexadecimal equivalent of every 4 digit binary number from left to right.
Step 3
Remove all spaces between the final output.
Example #1
Question: The given binary number is
11101010100011012. Find out its hexadecimal form.
Answer:
The number on partitioning will be written as,
1110 1010 1000 1101
The binary to hexadecimal conversion using the table is as follows,
1110
2 = E
16
1010
2 = A
16
1000
2 = 8
16
1101
2 = D
16
The final output (after removing the spaces) is,
1110101010001101
2 = EA8D
16
Example #2
Question: The given binary number is
10111011111001010111112. Find out its hexadecimal form.
Answer:
The number on partitioning and addition of zeroes will be written as,
0010 1110 1111 1001 0101 1111
The binary to hexadecimal conversion is as follows,
0010
2 = 2
16
1110
2 = E
16
1111
2 = F
16
1001
2 = 9
16
0101
2 = 5
16
1111
2 = F
16
The final output (after removing the spaces) is,
1011101111100101011111
2 = 2EF95F
16
How to Convert Hexadecimal to Binary
To convert a hexadecimal value to binary, you simply need to translate each hexadecimal digit into its 4-bit binary equivalent.
Example #1
Question: The given hexadecimal number is
6FD16. Find out its binary form.
Answer:
6
16 = 0110
2
F
16 = 1111
2
D
16 = 1101
2
The final output (with spaces) is,
6FD
16 = 0110 1111 1101
2
Example #2
Question: The given hexadecimal number is
8F4E9A16. Find out its binary form.
Answer:
8
16 = 1000
2
F
16 = 1111
2
4
16 = 0100
2
E
16 = 1110
2
9
16 = 1001
2
A
16 = 1010
2
The final output (with spaces) is,
8F4E9A
16 = 1000 1111 0100 1110 1001 1010
2
Hexadecimal Prefixes Explained
Prefix |
Use |
Example |
0x |
used in programming languages |
0x47DE |
% |
used in URLs to express characters like 'Space' |
%20 |
\x |
used to express character control codes |
'Backspace' (\x08), 'Escape' (\x1B), and 'Line Feed' (\x0A) |
# |
used to refer colors in HTML and other image editing programs |
#FF7734 |
0h |
used by many programmable graphic calculators |
0h7E |
|
used to represent unicode characters in HTML, XML, and XHTML |
prefixed to 3A9 prints an Ω. |
Always prepare and refer to the conversion chart while performing conversion between binary and hexadecimal numbers. This will simplify your task and ensure that no errors are introduced in your code.