How to Convert a Decimal Number to Hexadecimal

Table of contents:

How to Convert a Decimal Number to Hexadecimal
How to Convert a Decimal Number to Hexadecimal
Anonim

The hexadecimal is a positional numbering system based on 16. This means that to express the single digits there are 16 symbols, the classic decimal numbers (0-9) and the letters A, B, C, D, E and F. The conversion of a decimal number to hexadecimal is much more complex than the opposite operation. Be patient and take your time to learn the basic mechanics so you don't make any mistakes.

Conversion Table

Decimal System 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal system 0 1 2 3 4 5 6 7 8 9 TO B. C. D. AND F.

Steps

Method 1 of 2: Intuitive Method

Convert from Decimal to Hexadecimal Step 1
Convert from Decimal to Hexadecimal Step 1

Step 1. If you have little experience using the hexadecimal system (often abbreviated as ESA or HEX), start by using this conversion method

Of the two approaches described in this guide, this is the easiest for most people to follow. If you are already familiar with the different numbering systems, try using the quick method.

If this is your first time with the hexadecimal numbering system, it may help to understand its main concepts

Convert from Decimal to Hexadecimal Step 2
Convert from Decimal to Hexadecimal Step 2

Step 2. Write the list of powers of 16

Each single digit of a hexadecimal number represents a different power of 16, just as each decimal digit represents a power of 10. The following list of powers of 16 will come in handy when converting:

  • 165 = 1.048.576
  • 164 = 65.536
  • 163 = 4.096
  • 162 = 256
  • 161 = 16
  • If the decimal number to convert is greater than 1,048,576, calculate the next powers of 16 and add them to the list.
Convert from Decimal to Hexadecimal Step 3
Convert from Decimal to Hexadecimal Step 3

Step 3. Find the highest power of 16 contained in the decimal number to convert

Make a note of the decimal number in question. Refer to the list and find the largest power of 16 that is also small enough to fit the number you want to convert.

For example, if you want to convert the decimal number 495 in hexadecimal, you have to take 256 as the reference.

Convert from Decimal to Hexadecimal Step 4
Convert from Decimal to Hexadecimal Step 4

Step 4. Divide the decimal number by the power of 16 found

Just examine the whole part of the result, discarding any decimal numbers.

  • In our example we have 495 ÷ 256 = 1, 933593. As mentioned, we are only interested in the integer part of the result, so

    Step 1..

  • The result obtained corresponds to the first digit of the hexadecimal number. Since in this case we used the number 256 as a divisor, the number 1 obtained as a result corresponds to the power 162, that is, it is in the "post of 256".
Convert from Decimal to Hexadecimal Step 5
Convert from Decimal to Hexadecimal Step 5

Step 5. Calculate the remainder

This information shows the remainder of the decimal number still to be converted. Here's how to calculate it by simply doing division:

  • Multiply the result by the divisor. In our example 1 x 256 = 256 (in other words the digit 1 of our hexadecimal number represents the number 256 in base 10).
  • Subtract the result of the dividend. 495 - 256 = 239.
Convert from Decimal to Hexadecimal Step 6
Convert from Decimal to Hexadecimal Step 6

Step 6. Now divide the remainder by the highest power of 16 it can hold

To do this, refer again to the list of powers of 16 provided in the previous steps. Continue by finding the largest power of 16 that can be contained in the new number to convert. Divide the remainder by this number to find the next digit that makes up the hexadecimal number (if the remainder is less than the smallest power of 16 available, the next digit in the hexadecimal number is 0).

  • In our example we get 239 ÷ 16 =

    Step 14.. Also in this case we take into consideration only the integer part, discarding any decimal figure.

  • This is the second digit of our hexadecimal number (corresponding to the power 161, that is, it is in the "post of 16"). Any number in the 0-15 set can be represented by a single hexadecimal digit. We will convert it to the correct notation at the end of this section.
Convert from Decimal to Hexadecimal Step 7
Convert from Decimal to Hexadecimal Step 7

Step 7. Calculate the remainder again

As before, multiply the last result obtained by the divisor, then subtract the result from the dividend. The number obtained is the remainder of the original decimal number that we have yet to convert.

  • 14 x 16 = 224.
  • 239 - 224 =

    Step 15. (our rest).

Convert from Decimal to Hexadecimal Step 8
Convert from Decimal to Hexadecimal Step 8

Step 8. Repeat the previous step until you get a remainder that is less than 16

When you get a number between 0 and 15 as a remainder, you can convert it directly to hexadecimal using the conversion table at the beginning of the article. The figure obtained will be the last.

The last "digit" of our hexadecimal number is 15, which corresponds to the power of 160, that is, it is in the "position of 1".

Convert from Decimal to Hexadecimal Step 9
Convert from Decimal to Hexadecimal Step 9

Step 9. Write the conversion result respecting the correct notation

Now that we know all the digits that make up our hexadecimal number, we need to convert them to the correct notation (this is because they are still expressed in base 10). To do this, refer to this simple guide:

  • Numbers 0 to 9 remain unchanged.
  • The numbers from 10 to 15 are expressed in the following way: 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F.
  • In our example we have obtained the following digits: 1, 14, 15. Expressing them in the correct notation we obtain the hexadecimal number 1EF.
Convert from Decimal to Hexadecimal Step 10
Convert from Decimal to Hexadecimal Step 10

Step 10. Verify that your work is correct

Doing so is very simple once you understand the process behind the hexadecimal numbering system. Convert every single hexadecimal digit to decimal. To do this, multiply it by the power of 16 which corresponds to the position occupied. Here is the calculation to be performed based on our example:

  • 1EF → (1) (14) (15)
  • Perform the calculation starting from the right and moving to the left: 15 corresponds to the power 160, that is, it is in the "position of 1". 15 x 1 = 15.
  • The next digit corresponds to power 161, that is, it is in the "post of 16". 14 x 16 = 224.
  • The last digit corresponds to power 162, that is, it is in the "post of 256". 1 x 256 = 256.
  • By adding together the results obtained we will have 256 + 224 + 15 = 495, our starting decimal number.

Method 2 of 2: Quick Method

Convert from Decimal to Hexadecimal Step 11
Convert from Decimal to Hexadecimal Step 11

Step 1. Divide the decimal number by 16

Do this as a normal integer division. In other words, only take into account the whole part of the result and then calculate the rest, discarding the decimal places.

For example, let's say we want to convert the decimal number 317.547. Perform the following calculation 317.547 ÷ 16 = 19.846 (without worrying about the decimal places).

Convert from Decimal to Hexadecimal Step 12
Convert from Decimal to Hexadecimal Step 12

Step 2. Make a note of the rest in hexadecimal

After performing the first division, the integer result obtained will be the part of the decimal number from which you will get the hexadecimal digits that occupy the positions of 16 or subsequent ones. Consequently, the remainder of the division will represent power 160 of the hexadecimal number, that is the last figure.

  • To calculate the remainder of the division, multiply the result by the divisor and subtract it from the dividend. In our example we will get 317.547 - (19.846 x 16) = 11.
  • Convert the resulting figure into hexadecimal, which is still expressed in base 10, with the help of the conversion table available at the beginning of the article. In our example, the decimal number 11 corresponds to the B. hexadecimal.
Convert from Decimal to Hexadecimal Step 13
Convert from Decimal to Hexadecimal Step 13

Step 3. Repeat the previous step using the quotient as the starting point

For the moment we have converted the remainder of the first division to hexadecimal. Now it is necessary to continue dividing the quotient again by 16. The new remainder will be the penultimate digit of the final hexadecimal number. Also in this case we will use the same logical procedure seen previously: at this point the starting decimal number will have been divided by 16 twice, this means that the rest of the operation cannot contain the power 162 (16 x 16 = 256). We've already found the first digit of our hexadecimal number, so the rest of this is the power of 161, that is, it is in the "post of 16".

  • In our example we will get 19.846 / 16 = 1240.
  • The remainder will be equal to 19,846 - (1240 x 16) =

    Step 6.. This result represents the penultimate digit of our hexadecimal number.

Convert from Decimal to Hexadecimal Step 14
Convert from Decimal to Hexadecimal Step 14

Step 4. Repeat the previous steps until you get a quotient less than 16

Remember to convert the numbers 10-15 to hexadecimal notation. Report each of the remains in the order they were calculated. The final quotient (the one below 16) represents the first digit of your hexadecimal number. Here's what we get from our example:

  • Divide the last quotient again by 16. 1240 ÷ 16 = 77 with remainder

    Step 8..

  • Continue with the next operation: 77 ÷ 16 = 4 with remainder 13 = D. in hexadecimal.
  • Since 4 is less than 16,

    Step 4. is the first digit of our final number.

Convert from Decimal to Hexadecimal Step 15
Convert from Decimal to Hexadecimal Step 15

Step 5. Build the final number

Now that we have all the digits that make up our hexadecimal number, starting with the least significant to the most significant, make sure you write them in the correct order.

  • The final result is the following: 4D86B.
  • To verify the accuracy of your work, convert each digit back into the corresponding decimal number by multiplying it by the relative power of 16, then proceed by adding the results obtained: (4 x 164) + (13 x 163) + (8 x 162) + (6 x 16) + (11 x 1) = 317.547, exactly the starting decimal number.

Advice

To avoid getting confused when using different numbering systems, you should always specify the numbering base used as a subscript of the number. For example, 51210 means "512 base 10", which is an ordinary decimal number. The wording 51216 instead it means "512 base 16" and is equivalent to the decimal number 129810.

Recommended: