# How to Convert Decimal to Hexadecimal?

Digital ElectronicsComputer EngineeringMCA

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.

## Conversion from Decimal to Hexadecimal number system

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
= (1x26+1x25+0x24+0x23+1x22+0x21+0x20)10 or (1x82+4x81+4x80)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.

## (a) Converting with Remainders (For integer part)

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.

DivisionRemainder (R)
540 / 16 = 3312 = C
33 / 16 = 21
2 / 16 = 02
0 / 16 = 00

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.

## (b) Converting with Remainders (For fractional part)

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.

MultiplicationResultant integer part
0.06640625 x 16=1.06251
0.0625 x 16 =1.01
0 x 16=0.00

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

## Converting with Division

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.

• 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 163=4096 162=256 161=16 160=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 this
remainder 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.
Published on 06-Dec-2018 11:32:58