# Conversion of Decimal Number System into Hexadecimal Number System

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

Submitted by Saurabh Gupta, on October 12, 2019

**Conversion of decimal number system into hexadecimal number system** can be done by successively dividing an integral part by 16 till the quotient is 0 and then reading the remainder of all in the bottom to the top manner, where the bottom one is the MSB and the topmost is the LSB. For fractional part, we successively multiply it by 16 till we get 0 in the fractional part of the product term, the integral part of the product term recorded from top to bottom forms the respective hexadecimal number where topmost is the MSB.

To **convert a mixed decimal number into hexadecimal**, we will first convert integral and fractional parts into hexadecimal and then combine them.

The only thing to be kept in mind is the digits in hexadecimal number system are as:

**1 , 2, 3, 4, 5, 6, 7, 8, 9, 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F**

Now let's take examples to understand the **conversion of decimal number to hexadecimal number**.

**Example 1:**

**Convert (1954.785) _{10} to ( ? )_{16}**

**Solution:**

Given decimal number (1954.785)_{10} is of mixed type and contains both integral (1954)_{10} and decimal part (0.785)_{10}. To convert the given number into hexadecimal, we have to convert integral and fractional part individually into hexadecimal and then combine them together to get the required result.

**Integral Part**

Divisor | Quotient | Remainder |
---|---|---|

16 | 1954 | |

16 | 122 | 2 LSB |

16 | 7 | 10 = A |

16 | 0 | 7 MSB |

The remainders read from bottom to top gives the equivalent hexadecimal number i.e., **(1954) _{10} = (7A2)_{16}**.

**Fractional Part**

0.785 * 16 = 12.56 =C.56 (MSB) 0.56 * 16 =8.96 0.96 * 16 = 15.36 =F.36 0.36 * 16 =5.76 0.76 * 16 = 12.16 =C.16 (LSB)

The integer part of the product term read from top to bottom forms the equivalent hexadecimal number i.e., **(0.785) _{10} = (0.C8F5C)_{16}**.

After converting both integral part and fractional part individually into hexadecimal, now we combine both to get our desired result i.e., **(1954.785) _{10} = (7A2.C8F5C)_{16}**.

**Example 2:**

**Convert (3283.715) _{10} to ( ? )_{16}**

**Solution:**

**Integral Part**

Divisor | Quotient | Remainder |
---|---|---|

16 | 3283 | |

16 | 205 | 3 LSB |

16 | 12 | 13=D |

16 | 0 | 12=C MSB |

The remainders read from bottom to top gives the equivalent hexadecimal number i.e., **(3283) _{10} = (CD3)_{16}**.

**Fractional Part**

0.715 * 16 = 11.44 =B.44 (MSB) 0.44 * 16 =7.04 0.04 * 16 =0.64 0.64 * 16 = 10.24 =A.24 (LSB)

The integer part of the product term read from top to bottom forms the equivalent hexadecimal number i.e., **(0.715) _{10} = (0. B70A)_{16}**.

After converting both integral part and fractional part individually into hexadecimal, now we combine both to get our desired result i.e., **(3283.715) _{10} = (CD3. B70A)_{16}**.

**Example 3:**

**Convert (356.225) _{10} to ( ? )_{16}**

**Solution:**

**Integral Part**

Divisor | Quotient | Remainder |
---|---|---|

16 | 356 | |

16 | 22 | 4 LSB |

16 | 1 | 6 |

16 | 0 | 1 MSB |

The remainders read from bottom to top gives the equivalent hexadecimal number i.e., **(356) _{10} = (164)_{16}**.

**Fractional Part**

0.225 * 16 =3.600 (MSB) 0.600 * 16 =9.600 0.600 * 16 =9.600 0.600 * 16 =9.600 (LSB)

The integer part of the product term read from top to bottom forms the equivalent hexadecimal number i.e., **(0.225) _{10} = (0.39)_{16}**.

After converting both integral part and fractional part individually into hexadecimal, now we combine both to get our desired result i.e., **(356.225) _{10} = (164.39)_{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