- Related Questions & Answers
- How to Convert Hexadecimal to Decimal?
- How to convert Decimal to Hexadecimal in Java
- How to convert decimal to hexadecimal in JavaScript?
- Java Program to convert from decimal to hexadecimal
- Convert decimal integer to hexadecimal number in Java
- Java program to convert decimal number to hexadecimal number
- Java Program to convert hexadecimal number to decimal number
- Java Program to convert decimal integer to hexadecimal number
- How to Convert Decimal to Binary, Octal, and Hexadecimal using Python?
- How to Convert Binary to Hexadecimal?
- C++ program for hexadecimal to decimal
- How to Convert Binary to Decimal?
- How to Convert Decimal to Binary?
- How to Convert Decimal to Octal?
- Program for decimal to hexadecimal conversion in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

**Decimal** system is most familiar number system to the general public. It is base 10 which has only 10 symbols − 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. Whereas **Hexadecimal** system is most familiar number system color representation in Computers or digital systems. It is base 16 which has only 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and A, B, C, D, E, F. These A, B, C, D, E, F use as single digit in place of double digits, 10, 11, 12, 13, 14, 15 respectively.

There are various direct or indirect methods to convert a decimal number into hexadecimal number. In an indirect method, you need to convert a decimal number into other number system (e.g., binary or octal), then you can convert into hexadecimal number by using grouping from binary number system and converting each octal digit into binary then grouping and convert these into hexadecimal number.

**Example** − Convert decimal number 105 into hexadecimal number.

First convert it into binary or octal number, = (100)_{10}= (1x2^{6}+1x2^{5}+0x2^{4}+0x2^{3}+1x2^{2}+0x2^{1}+0x2^{0})_{10}or (1x8^{2}+4x8^{1}+4x8^{0})_{10}Because base of binary and octal are 2 and 8 respectively. = (1100100)_{2}or (144)_{8}Then convert each digit of octal number into 3 bit of binary number, then use grouping of 4 bit of binary number. = (1100100)_{2}or (001 100 100)_{2}= (110 0100)_{2}= (0110 0100)_{2}= (6 4)_{16}= (64)_{16}

However, there are two direct methods are available for converting a decimal number into Hexadecimal number − Converting with Remainders and Converting with Division. These are explained as following below.

This is a straightforward method which involve dividing the number to be converted. Let decimal number is N then divide this number from 16 because base of hexadecimal number system is 16. Note down the value of remainder, which will be: 0 to 15 (replace 10, 11, 12, 13, 14, 15 by A, B, C, D, E, F respectively). Again divide remaining decimal number till it became 0 and note every remainder of every step. Then write remainders from bottom to up (or in reverse order), which will be equivalent hexadecimal number of given decimal number. This is procedure for converting an **integer decimal** number, algorithm is given below.

Take decimal number as dividend.

Divide this number by 16 (16 is base of hexadecimal so divisor here).

Store the remainder in an array (it will be: 0 to 15 because of divisor 16, replace 10, 11, 12, 13, 14, 15 by A, B, C, D, E, F respectively).

Repeat the above two steps until the number is greater than zero.

Print the array in reverse order (which will be equivalent hexadecimal number of given decimal number).

Note that dividend (here given decimal number) is the number being divided, the divisor (here base of hexadecimal, i.e., 16) in the number by which the dividend is divided, and quotient (remaining divided decimal number) is the result of the division.

**Example** − Convert decimal number 540 into hexadecimal number.

Since given number is decimal integer number, so by using above algorithm performing short division by 16 with remainder.

Division | Remainder (R) |
---|---|

540 / 16 = 33 | 12 = C |

33 / 16 = 2 | 1 |

2 / 16 = 0 | 2 |

0 / 16 = 0 | 0 |

Now, write remainder from bottom to up (in reverse order), this will be 021C (or only 21C) which is equivalent hexadecimal number of decimal integer 540.

But above method can not convert fraction part of a mixed (a number with integer and fraction part) hexadecimal number. For **decimal fractional** part, the method is explained as following below.

Let decimal fractional part is M then multiply this number from 16 because base of hexadecimal number system is 16. Note down the value of integer part, which will be − 0 to 15 (replace 10, 11, 12, 13, 14, 15 by A, B, C, D, E, F respectively). Again multiply remaining decimal fractional number till it became 0 and note every integer part of result of every step. Then write noted results of integer part, which will be equivalent fraction hexadecimal number of given decimal number. This is procedure for converting an **fractional decimal** number, algorithm is given below.

Take decimal number as multiplicand.

Multiple this number by 16 (16 is base of hexadecimal so multiplier here).

Store the value of integer part of result in an array (it will be: 0 to 15, because of multiplier 16, replace 10, 11, 12, 13, 14, 15 by A, B, C, D, E, F respectively).

Repeat the above two steps until the number became zero.

Print the array (which will be equivalent fractional hexadecimal number of given decimal fractional number).

Note that a multiplicand (here decimal fractional number) is that to be multiplied by multiplier (here base of hexadecimal, i.e., 16)

**Example** − Convert decimal fractional number 0.06640625 into hexadecimal number.

Since given number is decimal fractional number, so by using above algorithm performing short multiplication by 16 with integer part.

Multiplication | Resultant integer part |
---|---|

0.06640625 x 16=1.0625 | 1 |

0.0625 x 16 =1.0 | 1 |

0 x 16=0.0 | 0 |

Now, write these resultant integer part, this will be approximate 0.110 which is equivalent hexadecimal fractional number of decimal fractional 0.06640625.

This method is guessing hexadecimal number of a decimal number. You need to draw a table of power of 16, For **integer part**, The algorithm is explained as following below.

Start with any decimal number.

List the powers of 16.

Divide the decimal number by the largest power of 16.

Find the remainder.

Divide the remainder by the next power of 16.

Repeat until you've found the full answer.

**Example** − Convert decimal number 380 into hexadecimal number.

According to above algorithm, table of power of 16,

Decimal | 16^{3}=4096 | 16^{2}=256 | 16^{1}=16 | 16^{0}=1 |

Hexadecimal Digit | 0 | 1 | 7 | C |

Divide the decimal number by the largest power of 16. = 380 / 256 = 1.484375 So 1 will be first digit or most significant bit (MSB) of hexadecimal number. Now, remainder will be, = 380 - 1256 =124 Now, divide thisremainder by the next power of 16. = 124 / 16 = 7.75 So 7 will be next digit or second most significant bit (MSB) of hexadecimal number. Now, remainder will be, = 124 - 716 = 12 Because remainder 12(= C) is less than base 16, so C(=12) will be ast (least significant) bit of required hexadecimal number. Therefore, 17C will be equivalent hexadecimal number of given decimal number 380.

Advertisements