Convert from decimal to hexadecimal

Author: John Pratt
Date Of Creation: 12 April 2021
Update Date: 1 July 2024
Anonim
How To Convert Decimal to Hexadecimal
Video: How To Convert Decimal to Hexadecimal

Content

Hexadecimal is a number system with the base sixteen. This means that there are 16 symbols to represent a number, with A, B, C, D, E and F added to the usual ten numbers. Converting from decimal to hexadecimal is more difficult than the other way around. Take the time to learn this as it is easier to avoid mistakes once you understand why the conversion works.

Small number conversions

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 a B. C. D. E F.

To step

Method 1 of 2: Intuitive method

  1. Use this method if you are new to hexadecimal numbers. Of the two approaches in this article, this is the easiest for most people to follow. If you are already familiar with the different bases, try the faster method as shown below.
    • If you are completely unfamiliar with hexadecimal numbers, learn the basic concepts first.
  2. Write down the powers of 16. Each digit within the hexadecimal system represents a different power of 16, just as a decimal digit is a power of 10. This list of powers of 16 comes in handy when converting:
    • 16 = 1.048.576
    • 16 = 65.536
    • 16 = 4.096
    • 16 = 256
    • 16 = 16
    • If the decimal number you are converting is greater than 1,048,576, calculate the higher powers of 16 and add it to the list.
  3. Find the highest power of 16 that fits within the decimal number. Write down the decimal number you want to convert. Use the above list for reference. Find the highest power of 16 that is less than the decimal number.
    • For example, if you 495 to hexadecimal, choose 256 from the list above.
  4. Divide the decimal number by this power of 16. Stop at the whole number and ignore every decimal point of the answer.
    • In our example, 495 ÷ 256 = 1.93 ..., but we're only interested in the whole number 1.
    • Your answer is the first digit of the hexadecimal number. In this case, since we divided by 256, the 1 is the number in the "256's place."
  5. Find the rest. This tells you what is left of the decimal number to convert. This is how you can calculate it, just like with long division:
    • Multiply your last answer by the divisor. In our example, 1 x 256 = 256. (In other words, the 1 of our hexadecimal number represents 256 with the base 10).
    • Subtract your answer from the dividend. 495 - 256 = 239.
  6. Divide the remainder by the next higher power of 16. Use your list of powers of 16 again as a reference. Continue to the smallest power of 16. Divide the remainder by that value to find the next digit in your hexadecimal number. (If the remainder is less than this number, the next digit is 0.)
    • 239 ÷ 16 = 14. Again, we ignore all decimal places.
    • This is the second digit of our hexadecimal number, the "16's." Any number from 0 to 15 can be displayed as a single hexadecimal digit. We convert to the correct format at the end of this method.
  7. Determine the rest again. As before, multiply the answer by the divisor and subtract it from the dividend. This is the rest that has yet to be converted.
    • 14 x 16 = 224.
    • 239 - 224 = 15, so the remainder is 15.
  8. Repeat until you have a remainder of less than 16. Once the remainder is 0 to 15, it can be expressed with a single hexadecimal digit. Write this down as the last digit.
    • The last "digit" of our hexadecimal number is 15, in place of the "units."
  9. Write your answer in the correct format. You now know what all the digits of your hexadecimal number are. But so far we've only written them in base ten. To write each digit in the correct hexadecimal format, convert them using this guide:
    • The numbers 0 to 9 remain the same.
    • 10 = A; 11 = B; 12 = C; 13 = D; 14 = E; 15 = F
    • In our example, we end with the numbers (1) (14) (15). In proper format, this will be the hexadecimal number 1EF.
  10. Check your work. Checking your answer is easy when you understand how hex numbers work. Convert each digit back to its decimal form, and multiply it by the 16th power for that base position. This is what we need to do for our example:
    • 1EF → (1) (14) (15)
    • From right to left, 15 is in the 16 = 1st position. 15 x 1 = 15.
    • The next digit from the left is in the 16 = 16th position. 14 x 16 = 224.
    • The next digit is in the 16 = 256th position. 1 x 256 = 256.
    • We add them all up, 256 + 224 + 15 = 495, our original number.

Method 2 of 2: Fast method (with remainder)

  1. Divide the decimal number by 16. Treat this division as an integer division. In other words, instead of calculating the decimal numbers, you stop at an integer answer.
    • For this example, let's get a little more ambitious and convert the decimal number 317,547. Calculate 317,547 ÷ 16 = 19.846, and ignore the decimal places.
  2. Write the rest in hexadecimal format. Now that you've divided the number by 16, the remainder is the part that no longer fits the 16's or higher's position. Therefore, the rest has to be in the position of the units, the last digit of the hexadecimal number.
    • To find the remainder, multiply the answer by the divisor and then subtract the result from the dividend. In our example, 317,547 - (19,846 x 16) = 11.
    • Convert the number to hexadecimal format using the small number conversion table at the top of this article page. 11 becomes B. in our example.
  3. Repeat this process with the quotient. You converted the rest to a hexadecimal digit. To continue converting the quotient, divide it by 16 again. The remainder is the penultimate digit of the hexadecimal number.This works according to the same logic as above: the original number has now been divided by (16 x 16 =) 256, so the remainder is the part of the number that fits the 256's position. We already know the units, the rest must be in the 16's place.
    • In our example, 19,846 / 16 = 1,240.
    • Rest = 19,846 - (1,240 x 16) = 6. This is the second to last digit of our hexadecimal number.
  4. Repeat this until you get a quotient less than 16. Don't forget to convert a remainder from 10 to 15 in hexadecimal format. Write down every rest along the way. The last quotient (less than 16) is the first digit of your number. We continue with the example:
    • Take the last quotient and divide it by 16 again. 1.240 / 16 = 77 remainder 8.
    • 77/16 = 4 rest 13 = D..
    • 4 16, so 4 is the first digit.
  5. Complete the number. As mentioned earlier, you determine each digit of the hexadecimal number from right to left. Check your work to make sure you wrote them in the correct order.
    • Our final answer is 4D86B.
    • To check your work, convert each digit back to the decimal number multiplied by powers of 16 and add the results. (4x16) + (13x16) + (8x16) + (6x16) + (11x1) = 317,547, our original decimal number.

Tips

  • To avoid confusion when using the different numeric systems, you can write the base as a subscript. For example, 51210 Then "512 with base 10," is an ordinary decimal number. 51216 means "512 with base 16," equivalent to the decimal number 1,29810.