Base 10 → base 16
Decimal to Hex Converter
Turn an ordinary number into hexadecimal, formatted the way your language or spec expects.
How to convert decimal to hex
The method is repeated division. Divide by 16, keep the remainder, divide the quotient by 16 again, and continue until the quotient reaches zero. The remainders spell the answer — read from the bottom up, not the top down.
- Divide the number by 16. Write down the whole-number quotient and the remainder.
- If the remainder is 10 or more, convert it to a letter: 10 is A, 11 is B, 12 is C, 13 is D, 14 is E, 15 is F.
- Divide the quotient by 16 and record the next remainder.
- Repeat until the quotient is 0.
- Read the remainders in reverse order. That is your hex value.
Reading the remainders in the order you produced them gives the digits backwards. The first remainder you calculate is the last digit of the answer, because it is the ones place.
Worked examples
6699 to hex
6699 ÷ 16 = 418 remainder 11 → B
418 ÷ 16 = 26 remainder 2 → 2
26 ÷ 16 = 1 remainder 10 → A
1 ÷ 16 = 0 remainder 1 → 1
read upwards → 1A2B
47 to hex
47 ÷ 16 = 2 remainder 15 → F
2 ÷ 16 = 0 remainder 2 → 2
read upwards → 2F
A faster route for small numbers
Anything below 256 fits in one byte, which is two hex digits, and you can split it without dividing twice. Take the number of whole 16s for the first digit and what is left for the second.
200 → 200 ÷ 16 = 12 remainder 8 → C8 47 → 47 ÷ 16 = 2 remainder 15 → 2F 255 → 255 ÷ 16 = 15 remainder 15 → FF
With the sixteen digit values memorised this becomes something you can do in your head, which is genuinely useful when reading color codes or byte values. The by-hand tutorial has practice problems if you want to drill it.
Quick reference
| Hex | Decimal | Binary | Octal |
|---|---|---|---|
| 0 | 0 | 0000 | 0 |
| 1 | 1 | 0001 | 1 |
| 2 | 2 | 0010 | 2 |
| 3 | 3 | 0011 | 3 |
| 4 | 4 | 0100 | 4 |
| 5 | 5 | 0101 | 5 |
| 6 | 6 | 0110 | 6 |
| 7 | 7 | 0111 | 7 |
| 8 | 8 | 1000 | 10 |
| 9 | 9 | 1001 | 11 |
| A | 10 | 1010 | 12 |
| B | 11 | 1011 | 13 |
| C | 12 | 1100 | 14 |
| D | 13 | 1101 | 15 |
| E | 14 | 1110 | 16 |
| F | 15 | 1111 | 17 |
Large numbers, and where other tools quietly fail
Many converters run on double-precision floating point, which stores integers exactly only up to 9,007,199,254,740,991 — that is 253 − 1. Past that point they round, and the failure is silent: you get a plausible hex string that is wrong in its lower digits.
This converter uses arbitrary-precision integers, so a forty-digit decimal number converts exactly. If you work with 64-bit identifiers, nanosecond timestamps or cryptographic values, the difference is not academic.
| Decimal | Hex | Fits in |
|---|---|---|
| 255 | FF | 8 bits |
| 65,535 | FFFF | 16 bits |
| 16,777,215 | FFFFFF | 24 bits (one RGB color) |
| 4,294,967,295 | FFFFFFFF | 32 bits |
| 18,446,744,073,709,551,615 | FFFFFFFFFFFFFFFF | 64 bits |
Negative numbers
Hexadecimal has no minus sign in practice. A negative value is written as its two's complement at a fixed bit width, which means you must decide the width before the question has an answer.
−1 as 8 bits → FF −1 as 16 bits → FFFF −1 as 32 bits → FFFFFFFF −128 as 8 bits → 80 −50 as 8 bits → 256 − 50 = 206 → CE
Type a negative number above and the converter picks the smallest standard width that holds it, then tells you which width it used.
Output formatting
The chips control presentation, not value. Which you want depends on where the result is going.
- Upper case is the norm in hardware documentation, memory dumps and assembly.
- Lower case is the norm in CSS, hashes, Git object IDs and modern codebases.
- 0x prefix is required for a numeric literal in C-family languages.
- Byte pairs pads to an even digit count and separates each byte, which is how you want to read anything representing data rather than a quantity.
Frequently asked questions
How do I convert decimal to hex by hand?
Divide by 16 repeatedly, writing down each remainder, until the quotient is zero. Then read the remainders from the last back to the first.
What is 255 in hex?
FF. Divided by 16 it gives 15 remainder 15, and 15 is F.
What is 1000 in hex?
3E8. That is 3 times 256, plus 14 times 16, plus 8.
Should hex letters be upper or lower case?
Either is correct. Upper case dominates in hardware and assembly, lower case in CSS, hashes and modern source code. The value is the same.
How do I write a negative number in hex?
Choose a bit width and use two's complement. At 8 bits -1 is FF; at 32 bits the same value is FFFFFFFF. Without a stated width the question is incomplete.
Why does my result differ from another converter?
Usually a precision limit. Tools built on floating point lose accuracy above roughly nine quadrillion. This one uses exact integer arithmetic at any size.