Decimal to Hex Converter
To convert decimal to hex, divide the number by 16, write down the remainder as a hex digit (10–15 become A–F), and repeat with the quotient until it reaches 0. Read the remainders from last to first: 2024 gives remainders 8, 14 (E) and 7, so 2024 is 7E8 in hex.
Widths apply to whole numbers.
Repeats forever:
Unsigned:
Repeats forever:
Method: Repeated division by 16
| Divide | Quotient | Remainder | Digit |
|---|---|---|---|
| 2024 ÷ 16 | 126 | 8 | 8 |
| 126 ÷ 16 | 7 | 14 | E |
| 7 ÷ 16 | 0 | 7 | 7 |
Read the remainders from the bottom up: 7E8.
How to convert decimal to hex by hand
Converting decimal to hexadecimal is repeated division by 16, and division peels digits off the right end. Each remainder is what does not fit into a whole sixteen, so it is exactly the ones digit of what is left, and the quotient carries everything else one place to the right.
- Divide the decimal number by 16 and note the whole quotient and the remainder.
- Write the remainder as one hex digit, using A–F for 10 to 15.
- Divide the quotient by 16 again, and keep going until the quotient is 0.
- Read the remainders from the last one to the first; that string is the hex number.
The order trips people up more than the arithmetic does. The first remainder you write down is the last hex digit, so either fill the answer in from right to left, or stack the rows and read upward. A quick check: the answer has as many digits as divisions you made.
If you know the powers of 16, subtraction works too. 2024 holds seven 256s (1792), leaving 232, which holds fourteen 16s (224) and 8 over: 7, E, 8.
Worked example: 2024
Three divisions, so three hex digits
202410 = 7E816
| Divide | Quotient | Remainder | Digit |
|---|---|---|---|
| 2024 ÷ 16 | 126 | 8 | 8 |
| 126 ÷ 16 | 7 | 14 | E |
| 7 ÷ 16 | 0 | 7 | 7 |
Read the remainders from the bottom up: 7E8.
Decimal fractions: multiply instead of divide
Digits after the point come out of multiplication. Multiply the fraction by 16; the whole part of the product is the next hex digit, and the fractional part goes on to the next row. Stop when the fraction reaches zero.
Many tidy decimals never reach zero. One tenth is the usual surprise: after the first digit the same remainder, six tenths, keeps returning, so the digit 9 repeats forever. That is why 0.1 cannot be stored exactly in a binary float either. The converter detects the loop and writes the result as 0.1(9), with the repeating part in brackets.
The remainder 0.6 comes back after the second row
0.110 = 0.1(9)16
The whole part is 0, so the hex number starts 0.
| Multiply | Product | Digit |
|---|---|---|
| 0.1 × 16 | 1.6 | 1 |
| 0.6 × 16 | 9.6 | 9 |
The row 0.6 comes back, so the digits from there repeat forever.
Negative decimals: pick a width, invert, add one
A minus sign has no hex digit, so code stores negative integers as two’s complement bit patterns of a fixed size. The recipe needs the width first: write the magnitude in that many bits, flip every bit, then add 1.
At 8 bits, −42 becomes D6; at 16 bits the same number is FFD6, because the extra high bits are all ones. In the converter, choose the width chip and type the negative number into the decimal field. Without a width it shows −2A, the sign-and-magnitude form.
−4210 at 8 bits = D616
| Step | Bits |
|---|---|
| Write 42 in 8 bits | 0010 1010 |
| Invert every bit | 1101 0101 |
| Add 1 | 1101 0110 |
Read the bits in groups of four: D6.
Questions people ask
How do you write 20 in hexadecimal?
14. Dividing 20 by 16 gives 1 remainder 4, and dividing 1 by 16 gives 0 remainder 1. Reading the remainders from last to first gives 14, often written 0x14.
What is 255 in hex?
FF. 255 ÷ 16 is 15 remainder 15, and 15 ÷ 16 is 0 remainder 15. Fifteen is the digit F, so both digits are F.
How do you convert a negative decimal number to hex?
Pick a bit width, write the magnitude in binary, invert every bit and add 1. For −42 at 8 bits: 42 is 00101010, inverted it is 11010101, and adding 1 gives 11010110, which is D6 in hex.
How do you convert a decimal fraction to hex?
Multiply the fractional part by 16; the whole-number part of the product is the next hex digit. Repeat with what is left. For 0.1 you get 1.6, then 9.6, then 9.6 again forever, so 0.1 is 0.1999… in hex, written 0.1(9).
Related conversions
Last updated