# Conversion of Binary Number System into Hexadecimal Number System

Here, we are going to learn **how to convert from Binary Number System into Hexadecimal Number System?**

Submitted by Saurabh Gupta, on October 15, 2019

**Converting binary numbers into hexadecimal numbers** is similar to the conversion of binary into octal, it just requires some modifications. The relationship between binary numbers and hexadecimal numbers is given as:

Decimal | Hexadecimal | Binary |

0 | 0 | 0000 |

1 | 1 | 0001 |

2 | 2 | 0010 |

3 | 3 | 0011 |

4 | 4 | 0100 |

5 | 5 | 0101 |

6 | 6 | 0110 |

7 | 7 | 0111 |

8 | 8 | 1000 |

9 | 9 | 1001 |

10 | A | 1010 |

11 | B | 1011 |

12 | C | 1100 |

13 | D | 1101 |

14 | E | 1110 |

15 | F | 1111 |

In hexadecimal number system, we have sixteen digits ranging from **0 to 15** which can be represented using **four-bit binary numbers** in **2 ^{4} = 16** ways, so starting from the least significant bit of the binary number, we group four successive bits of the binary number to get its equivalent hexadecimal number as seen from the table above.

In an integral part, the grouping of four bits is done from the right side to the left side whereas in the fractional part the grouping of four bits is done from left to right and then convert it to its equivalent hexadecimal symbol.

In the process of grouping four bits, one/two/three bits can be added to the left of the MSB in an integral part and/or to the right of the LSB bit of the fractional part of the binary number.

Note: Whenever we need any additional bits, we only add '0' as the additional bit.

**Example 1: Convert (01111111.1010) _{2} to ( ? )_{16}**

**Solution:**

We will make a grouping of 4 bits from right to left direction in an integral part and from left to right direction in the fractional part and then replace it with the corresponding symbol with the help of the table provided above.

Therefore, **(01111111.1010) _{2} = (7F. A)_{16}**

**Example 2: Convert (1110011100.110001) _{2} to ( ? )_{16}**

**Solution:**

The given binary number consists of only 10 bits in an integral part and only 6 bits in the fractional part. So, making a group of 4 bits is not possible. In this case, we have to add bits from our side so that we can make a grouping of 4 bits. Thus, we add two zero bits at the LHS of the MSB in the integral part which will make 12 bits in an integral part, without disturbing its original value. Similarly, two zero bits are added to the RHS of the LSB in the fractional part, which will result in 8 bits in the fractional part and can be grouped in a group of 4 bits.

Thus, above given binary number can now be written as: **(001110011100.11000100) _{2}**

Therefore, **(001110011100.11000100) _{2} = (39C.C4)_{16}**

**Example 3: Convert (100101011110.0110111) _{2} to ( ? )_{16}**

**Solution:**

Given binary number has 12 bits in an integral part, so it can be easily grouped in a group of 4 bits but there are only 7 bits in the fractional part so we need to add one more additional zero bit to the RHS of LSB in the fractional part. Thus, the above binary number can now be written as: **(100101011110.01101110) _{2}**

Therefore, **(100101011110.01101110) _{2} = (95E.6E)_{16}**

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.