Colors, memory addresses and byte values are usually written in hexadecimal, and a decimal to hex converter turns an ordinary base-10 number into that base-16 form. Type a number above to get its hex value, with every division by 16 shown and the two's complement patterns for negative numbers. Below are three ways to convert decimal to hex by hand, and the values you'll meet most often.
Method 1: divide by 16
The standard method is repeated division. Divide your number by 16, write down the remainder, then divide the quotient by 16 again. Stop when the quotient reaches 0. The remainders are the hex digits, read from the last one back to the first, with 10 to 15 written as A to F. For 1,000: 1,000 ÷ 16 = 62 remainder 8, 62 ÷ 16 = 3 remainder 14, and 3 ÷ 16 = 0 remainder 3. Reading upward gives 3, 14 and 8, so 1,000 is 3E8. Larger numbers just take more steps. 48,879 leaves 15, 14, 14 and 11, which spells BEEF.
Method 2: subtract powers of 16
If you know the powers of 16 (1, 16, 256, 4,096, 65,536), you can build the hex number from the left instead. Find the largest power that fits, see how many times it fits, and carry the rest down. For 1,000, 256 fits 3 times (768), leaving 232. Then 16 fits 14 times (224), so the next digit is E, leaving 8 for the ones place. The result is again 3E8. This method is handy for checking an answer, because each digit's value is easy to see.
Method 3: go through binary
Every hex digit is exactly four bits, so if you already have the binary, converting to hex is quick. 1,000 in binary is 1111101000. Split it into groups of four from the right, 11 1110 1000, and replace each group with its hex digit: 3, E and 8. The decimal to binary converter gives the bits, and the binary to hex converter does the grouping.
Common decimal values in hex
| Decimal | Hex |
|---|---|
| 10 | A |
| 15 | F |
| 16 | 10 |
| 100 | 64 |
| 255 | FF |
| 256 | 100 |
| 1,000 | 3E8 |
| 4,096 | 1000 |
| 65,535 | FFFF |
| 1,000,000 | F4240 |
Notice that 16, 256 and 4,096 are written 10, 100 and 1000 in hex, just as 10, 100 and 1,000 are round numbers in decimal.
Checking your answer
It's easy to check a conversion by going back the other way. Multiply each hex digit by its power of 16 and add them up: 3E8 is 3 × 256 + 14 × 16 + 8 × 1, which is 768 + 224 + 8 = 1,000. You can also predict how many digits the answer needs. Each extra hex digit multiplies the range by 16, so n digits hold every number up to 16ⁿ − 1. Two digits go up to 255, three up to 4,095 and four up to 65,535. Since 1,000 is between 256 and 4,095, it needs three hex digits. The hex to decimal converter shows that working for any value.
Negative numbers in hex
Mathematically, a negative number in hex simply keeps its minus sign: −42 is -2A. Computers store negative integers in two's complement instead, in a fixed number of bits. −42 is D6 in 8 bits, FFD6 in 16 bits and FFFFFFD6 in 32 bits, and −1 is all F's at every width. To find the pattern, add 2 to the power of the width: −42 + 256 = 214, which is D6. The Signed and unsigned table under the converter shows all four widths, and the two's complement calculator walks through the encoding.
Where you'll convert decimal to hex
- Colors. CSS color values are three bytes in hex. Red 255, green 128 and blue 0 become
#FF8000. The RGB to hex converter does this for whole colors. - Unicode and HTML. Code points are written in hex, so character 233 is
U+00E9, and HTML acceptséfor é. - Programming. Bit masks, flags and memory sizes are clearer in hex: 65,535 is
0xFFFF, and 4,096 is0x1000.
Getting the format you need
- Turn on Add 0x prefix for a value you can paste straight into code, and switch off Uppercase for lowercase letters.
- Numbers of any size convert exactly, so values beyond 2⁵³ won't be rounded the way they are in many calculators.
- For decimal to binary, octal and hex together, use the hex converter.
Checking an answer takes seconds the other way round: the hex to decimal converter multiplies each digit back out by its power of 16.