Decimal to Hex
Paste decimal numbers, one per line or split by commas. Get exact hex values and the steps. Nothing leaves your browser.
Also: All bases, Hex to Dec, Bin to Dec, Dec to Bin, Hex to Bin, Bin to Hex
- 0
- Numbers
- 0
- Max bits
- 0
- Errors
On this page
About Decimal to Hex
Updated
Decimal to Hex turns ordinary numbers into hexadecimal. Paste one, or a whole column from a spreadsheet or a database. Every line is converted, exact to the last digit, even for 64-bit IDs that other converters round.
Turn on Prefix to get 0x in front, or switch to lower case for code that wants 0xff. Set Signed to write negative numbers the way a computer stores them.
The same tool, set up for other bases: Hex to Decimal, Binary to Decimal, Decimal to Binary, Hex to Binary, Binary to Hex, Number Base Converter.
How to use it
- Paste decimal numbers, one per line, or load a file. Commas, tabs and semicolons also split a line, so a column from a spreadsheet works.
- Check From and To, next to Convert. On a phone they are under More.
- Press Convert (Alt C). Results shows every number in the To base and in decimal, hex, binary and octal. Output shows only the answers, line for line, for Copy and Download.
- Open Steps to see the math for one number, the way you would do it on paper.
- Swap (Alt S) puts the answers in the editor and turns From and To around, so you can check the way back.
- In Options: Signed for two's complement, Groups for 1111 0000 or 4,294,967,295, Prefix for 0x, 0b or 0o, and how many digits a fraction gets.
How to convert decimal to hex by hand
Divide by 16 and keep the remainder each time. When the answer is 0, read the remainders from the bottom up:
2014 ÷ 16 = 125 remainder 14 → E
125 ÷ 16 = 7 remainder 13 → D
7 ÷ 16 = 0 remainder 7 → 7
Read from the bottom up: 7DECheck the answer the other way: 7 × 256 + 13 × 16 + 14 = 2014. Swap does this for a whole list in one press.
Decimal to hex chart
Dec Hex Dec Hex Dec Hex Dec Hex
0 0 16 10 100 64 1,000 3E8
9 9 32 20 127 7F 4,096 1000
10 A 50 32 128 80 10,000 2710
11 B 64 40 200 C8 65,535 FFFF
15 F 99 63 255 FF 1,000,000 F4240Negative numbers and two's complement
Set Signed to write a negative number the way a computer stores it. At 16-bit, -1 is FFFF and -255 is FF01.
How two's complement works, with a table and the method by hand.
Exact for big numbers
Database IDs often pass 2^53. This tool uses BigInt, so 9007199254740993 gives 20000000000001. A converter built on JavaScript numbers rounds it first and gives 20000000000000.
Why other converters round past 2^53.
Common errors
Scientific notation
A spreadsheet or a log can write one million as 1e6. The tool reads only plain digits, so it tells you what to do.
1e6
Scientific notation is not read. Write 1e6 in full, with all its digits.1000000A hex letter in a decimal number
Decimal has no letters. A number such as 1A is hex, so open Hex to Decimal for it, or set From to Hex.
1A
A is not a decimal digit. Decimal uses 0 to 9. Remove the A,
or set From to base 11 or more.The letter O for a zero
Typed by hand, a capital O and a zero look the same. The tool names the letter, so you know what to type.
12O4
The letter O is not a digit. Type the digit 0 (zero) in its place.1204Two numbers on one line
A space can group the digits of a big number, as in 4 294 967 295. When the groups are not all 3 digits, the tool still reads one number, 2811 in hex here, but marks the line, because it may be a list.
10 25 7
Read as one number, 10257. If these are separate numbers, put each on
its own line or split them with commas.10, 25, 7A number too big for its bits
With Signed set to a width, every number must fit in it. The message gives the range.
300 (Signed: 8-bit)
300 does not fit in signed 8 bits. Signed 8-bit numbers go from -128 to 127.
Pick a wider Signed setting, or set it to Off.Decimal to hex in code and Excel
JavaScript (255).toString(16) // "ff"
9007199254740993n.toString(16) // exact past 2^53
Python hex(255) # '0xff'
format(255, "X") # 'FF'
C printf("%02X", 9) // 09, two digits
Java Integer.toHexString(255) // "ff"
Excel =DEC2HEX(255) → FF
=DEC2HEX(9, 2) → 09DEC2HEX works from -549,755,813,888 to 549,755,813,887. A negative number comes back as 10 hex digits in two's complement: =DEC2HEX(-1) is FFFFFFFFFF. In Java, Integer.toHexString(-1) gives the 32-bit form, ffffffff.
Decimal to hex resources
- Hexadecimal on WikipediaWhy programmers write in base 16, the prefixes in each language, and how hex maps to bits.
- MDN: Number toString()(255).toString(16) writes a number in any base from 2 to 36 in JavaScript.
- Python: hex()hex(255) gives '0xff'. Use format(255, "x") for the digits with no prefix.
- Web colors on WikipediaHow #RRGGBB codes work: one byte, two hex digits, for each of red, green and blue.
- Microsoft: DEC2HEX functionDecimal to hex in Excel, from -549,755,813,888 to 549,755,813,887, with leading zeros if you ask.
Decimal to hex FAQ
How do I convert decimal to hex?
Divide the number by 16 and write down the remainder. Divide the answer by 16 again, until it is 0. The remainders are the hex digits, read from the bottom up; 10 to 15 are written A to F.
For 2014: 2014 ÷ 16 = 125 remainder 14 (E), 125 ÷ 16 = 7 remainder 13 (D), 7 ÷ 16 = 0 remainder 7. From the bottom up: 7DE. Open Steps to see it for your number.
What is 20 in hex?
Decimal 20 is hex 14: 20 ÷ 16 = 1 remainder 4. Check it the other way: 1 × 16 + 4 = 20.
How do I write 255 in hex?
255 is FF: 255 ÷ 16 = 15 remainder 15, and 15 is F. It is the largest number one byte holds, so it shows up in colors (#FFFFFF is white) and masks (0xFF).
How do I turn RGB values into a hex color code?
Convert each of the three values, red, green and blue, to two hex digits, and put them together after a #. Paste them split by commas, for example 255, 87, 51: the tool gives FF, 57 and 33, so the color is #FF5733. A value under 16 is one hex digit, so put a 0 in front of it in the color: 9 becomes 09.
How do I convert a negative number to hex?
In code, negative numbers are stored in two's complement. Set Signed to the width you need: in 16 bits -1 is FFFF, in 32 bits it is FFFFFFFF. With Signed off, the tool keeps the minus sign: -255 is -FF.
Can decimal fractions be converted to hex?
Yes. 0.5 is 0.8 and 3.75 is 3.C. But 0.1 has no end in hex: it is 0.1999... with the 9 repeating forever. The tool cuts it after 16 digits (8 to 64 in Options) and says which digits repeat.
Are my numbers sent anywhere?
No. The numbers are converted in your browser, with JavaScript BigInt. Nothing is uploaded, and there are no ads or cookie walls. You can check this in your browser's network tab while you use it.