The Wayback Machine - https://web.archive.org/web/20250102143000/https://www.geeksforgeeks.org/how-to-convert-binary-to-hexadecimal/
Open In App

How to convert Binary to Hexadecimal?

Last Updated : 01 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Number Systems are a major part of mathematics. The number system and its conversions are used in the various fields of mathematics and computer science. The binary number system is a system in which numbers are expressed in the base 2.

This article is about the binary, hexadecimal, and conversion of binary to the hexadecimal number system. The binary-to-decimal conversion is very easy and is explained further.

Decimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010

The hexadecimal number system is a system in which numbers are expressed in the base 16. In the hexadecimal number system, the numbers are represented in terms of 0-9 and A – F. The hexadecimal number is written as number H, (number)16, (number)H. Example: (A23F)16,

Decimal Hexadecimal
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A

Conversion of Binary to Hexadecimal 

Method 1

  1. Firstly, convert the given binary number into decimal.
  2. Then, convert the obtained decimal into hexadecimal.

Example: (1110)2 = (_______)16

First convert (1110)2 into decimal = (1110)2 = 23 × 1 + 22 × 1 + 21 × 1 + 20 × 0 = 8 + 4 + 2 + 0 = (14)10

Then, convert (14)10 into hexadecimal = (14)10 = (E)16

Example 2 : (0.11001)2 = (_________)16

First convert (0)2 to decimal = 0*20 = (0)10

Then convert (11001)2 to decimal = 1*2-1 + 1*2-2 + 0*2-3 + 0*2-4 + 1*2-5 = (0.78125)10

Now, convert (0)10 into hexadecimal   = (0)16

Now convert (.78125)10  to hexadecimal

0.78125*16 = 12.5

0.5*16 = 8.0

(.78125)10 to hexadecimal = (.C8)16

where C for 12 and 8 for 8

So  (0.11001)2 = (0.C8)16

Method 2: (Direct Method for converting binary to hexadecimal) 

Take the given binary number and form the collection of four bits called a quad, then replace the quad with its hexadecimal equivalent. Hence, the obtained number is the conversion of a given binary to hexadecimal.

Note

  • If, while forming the quad, the bits are before the radix point, then start forming the quad from the LSB bit and if the bits are after the radix point, start forming the quad from the immediate bit after the radix point.
  • While forming the quad, the number of bits is less than 4 and before the radix point, then add 0s before the fewer bits to form a quad.
  • While forming the quad, the number of bits is less than 4 and after the radix point then, add 0s after the fewer bits to form a quad.
Decimal Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A

Example: (11101111.111001)2 = (_______)16 

1110 1111.1110 01
1110 1111 1110  0100
  E      F   E       4 
(11101111.111001)2 = (EF.E4)16

We added two zeros at the last as we have only 01, which does not make a quad. 0s are added after 01 because it is after the radix point.

Sample Questions

Question 1: Convert: (111111101)2 = (_________)16

Solution:

(111111101)2 = 0001 1111 1101  (The bold three 0s are added before 1 as it is integral part (before the radix point))

= 1 F D

= (111111101)2 = (1FD)16

Question 2: Convert: (01011110001)2 = (_________)16

Solution:

(01011110001)2 = 0010 1111 0001 (The bold one 0s are added before 1 as it is integral part (before the radix point))

= 2 F 1

= (01011110001)2 = (2F1)16

Question 3: Convert: (0.11001)2 = (_________)16

Solution:

(0.11001)2 = 0000 . 1100 1000  (The bold three 0s are added before 0 as it is an integral part (before the radix point), and 3 bold 0s are added after 1 as 1 is after the radix point).

= 0 C 8

(0.11001)2 = (0.C8)16

Question 4: Convert: (1.1)2 = (_______)16

Solution:

(1.1)2 = 0001 . 1000 (The bold three 0s are added before 1 as it is an integral part (before the radix point), and 3 bold 0s are added after 1 as 1 is after the radix point).

= 1 8

= (1.1)2 = (1.8)16

Conclusion

Converting binary to hexadecimal is a simple process that utilizes grouping and direct conversion through the lookup table. This method is efficient and commonly used in the computing and digital electronics due to the compact nature of hexadecimal representation compared to binary.

FAQs on Binary to Hexadecimal Conversion

Why do we use hexadecimal in computing?

The Hexadecimal is more compact than binary and easier for humans to read and write. Each hexadecimal digit represents four binary digits making it a shorthand for the binary data.

Can you convert binary to hexadecimal without grouping?

No, grouping is essential for accurate conversion. Each group of four binary digits directly corresponds to the single hexadecimal digit.

What if the binary number has fewer than four digits?

If there are fewer than four digits simply add leading zeros to the left until the group has four digits.



Next Article

Similar Reads

three90RightbarBannerImg