How to convert decimal to hex
- Enter a decimal number, or a list with one number per line. Negative numbers and fractions such as
0.75work too. - The hex result appears instantly, along with binary and octal. The step-by-step table shows every division by 16 and its remainder.
- For the two's-complement hex of a negative number, tick Signed (two's complement) and choose the bit width: −1 becomes
FFin 8 bits andFFFFFFFFin 32 bits.
How to convert decimal to hexadecimal by hand
Use repeated division by 16:
- Divide the number by 16 and write down the remainder (0–15).
- Divide the quotient by 16 again, and repeat until the quotient is 0.
- Write each remainder as a hex digit (10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F) and read them from the last to the first.
Example: convert 6719 to hex.
| Division | Quotient | Remainder |
|---|---|---|
| 6719 ÷ 16 | 419 | 15 = F |
| 419 ÷ 16 | 26 | 3 |
| 26 ÷ 16 | 1 | 10 = A |
| 1 ÷ 16 | 0 | 1 |
Reading the remainders from bottom to top gives 1A3F. Check: 1 × 4096 + 10 × 256 + 3 × 16 + 15 = 6719.
Decimal fractions in hex
For the part after the decimal point, multiply by 16 instead of dividing: the whole-number part of each product is the next hex digit. 0.75 × 16 = 12, so 0.75 = 0.C in hex.
Some fractions never end in hex. 0.1 × 16 = 1.6 gives the digit 1, then 0.6 × 16 = 9.6 gives 9, and the 9 repeats forever, so 0.1 = 0.1999…. The converter rounds such values to 12 hex digits (0.19999999999A) and marks them with ≈.
Negative decimal numbers in hex (two's complement)
Computers store a negative number −n in w bits as 2ʷ − n. To find the pattern, add 2ʷ to the negative value and convert the result to hex: −26 in 8 bits is 256 − 26 = 230 = E6.
| Decimal | 8-bit | 16-bit | 32-bit |
|---|---|---|---|
| −1 | FF | FFFF | FFFFFFFF |
| −2 | FE | FFFE | FFFFFFFE |
| −26 | E6 | FFE6 | FFFFFFE6 |
| −128 | 80 | FF80 | FFFFFF80 |
Frequently asked questions
What is 255 in hex?
255 in hex is FF: 255 ÷ 16 = 15 remainder 15, then 15 ÷ 16 = 0 remainder 15, and both remainders are written as F. FF is the largest value of one byte.
How do I convert decimal to hex in Excel, Python or JavaScript?
Excel and Google Sheets: =DEC2HEX(255) gives FF. Python: format(255, 'X') gives FF and hex(255) gives 0xff. JavaScript: (255).toString(16) gives ff. In Excel, negative numbers come out as 10-digit two's complement: =DEC2HEX(-1) is FFFFFFFFFF.
Why does 0.1 not convert exactly to hex?
Because 1/10 cannot be written as a finite sum of sixteenths, 256ths and so on, its hex digits repeat forever (0.1999…), just like 1/3 = 0.333… in decimal. Fractions built from halves, quarters, eighths or sixteenths are exact: 0.5 = 0.8 and 0.75 = 0.C in hex.
Can I convert very large numbers?
Yes. The converter uses arbitrary-precision arithmetic, so 18446744073709551616 (2⁶⁴) gives exactly 10000000000000000 – far beyond the 2⁵³ limit of ordinary JavaScript numbers.