What is Decimal to Hex Converter?
This decimal to hexadecimal converter turns base-10 integers, called denary numbers in GCSE courses, into base 16 (hex). Hexadecimal is how programmers write colors (#FF8800), memory addresses, byte values, Unicode code points and IDs, because two hex digits describe exactly one byte. 255 becomes FF, 500 becomes 1F4 and 4096 becomes 1000.
Enter one number or many separated by spaces or commas, and each is converted at once. Options let you choose uppercase or lowercase letters, add the 0x prefix used in code and pick how results are separated.
How to use Decimal to Hex Converter
- Enter decimal numbers separated by spaces or commas, for example 255 500
- Read the hexadecimal results.
- Turn on the 0x prefix, change the case or the separator as needed.
- Copy the result, or click Swap to convert hex to decimal.
Key features
- Convert many values at once, separated by spaces or commas
- Exact results for numbers of any size, including 64-bit values
- Output separated by spaces, commas, new lines or nothing
- Uppercase or lowercase hex, optional 0x prefix, and binary padded to whole 8-bit bytes
- Swap button to reverse the conversion direction
- Summary of a single value in binary, octal, decimal, hex and ASCII
- Clear errors for invalid digits; runs entirely in your browser
Common use cases
- Converting RGB channel values (0–255) into hex color codes
- Writing byte values and constants in hex for code
- Turning decimal error codes and IDs into hex for documentation
- Finding the hex code point of a Unicode character
- Learning base conversion for computer science courses
Technical details & standards
To convert by hand, divide the number by 16 repeatedly and write down the remainders, using A to F for 10 to 15, then read them from last to first. For 500: 500 ÷ 16 = 31 remainder 4; 31 ÷ 16 = 1 remainder 15 (F); 1 ÷ 16 = 0 remainder 1, so the answer is 1F4.
Each value is converted as a whole number, so 65535 becomes FFFF. The arithmetic uses arbitrary-precision integers, so numbers beyond 9,007,199,254,740,991 (2^53 − 1), the largest integer ordinary JavaScript numbers hold exactly, still convert exactly: 18446744073709551615 becomes FFFFFFFFFFFFFFFF. Negative numbers are shown with a minus sign rather than in two's complement; use the Programmer Calculator to see bitwise representations.
Convert decimal to hex by hand: divide by 16
Working out dec to hex on paper means dividing by 16 until nothing is left. Each remainder is one hex digit, and the remainders come out in reverse order. Here is 50000, a number that needs four hex digits:
- Divide 50000 by 16: the quotient is 3125 and the remainder is 0.
- Divide 3125 by 16: the quotient is 195 and the remainder is 5.
- Divide 195 by 16: the quotient is 12 and the remainder is 3.
- Divide 12 by 16: the quotient is 0 and the remainder is 12, which is written C because hex uses A–F for 10–15.
- The quotient is 0, so stop. Read the remainders from the last one to the first: C, 3, 5, 0.
Result: 50000 in decimal is C350 in hex (0xC350). To check it, multiply back: 12 × 4096 + 3 × 256 + 5 × 16 + 0 = 50000. Type 50000 into the converter above to see the same steps worked out for you.
Decimal to hex in JavaScript, Python, C and Excel
Every mainstream language and spreadsheet has a built-in for this, so you rarely need the division loop in real code. Each line below gives the hex shown beside it.
JavaScript
(255).toString(16).toUpperCase(); // "FF"
(50000).toString(16).padStart(8, "0"); // "0000c350"
BigInt("18446744073709551615").toString(16); // "ffffffffffffffff"Use BigInt for values above 2^53 − 1; ordinary numbers lose precision there.
Python
hex(255) # '0xff'
format(50000, "X") # 'C350'
f"{4096:#06x}" # '0x1000'C
#include <stdio.h>
int main(void) {
unsigned int n = 50000;
printf("%X\n", n); /* C350 */
printf("0x%08X\n", n); /* 0x0000C350 */
printf("%X\n", (unsigned int)-1); /* FFFFFFFF */
return 0;
}%X prints uppercase hex and %x lowercase. Casting −1 to unsigned shows its 32-bit two's complement form.
Excel
=DEC2HEX(255) → FF
=DEC2HEX(50000, 8) → 0000C350
=DEC2HEX(-1) → FFFFFFFFFFDEC2HEX accepts −549,755,813,888 to 549,755,813,887 and returns #NUM! outside that range. Negative numbers come back as 10 hex digits, the 40-bit two's complement form.
Decimal to hex conversion table
Decimal 0 to 15 map to the single hex digits 0 to F; from 16 on, hex needs a second digit. The second table lists decimal numbers that are often written in hex, in code, colors and memory sizes.
Decimal 0–15 in hex and binary
| Decimal | Hex | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| 10 | A | 1010 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
Common decimal values in hex
| Decimal | Hex | Where you see it |
|---|---|---|
| 13 | 0x0D | ASCII carriage return (\r) |
| 16 | 0x10 | The first two-digit hex number |
| 23 | 0x17 | 1 × 16 + 7, so the digits read 17 |
| 32 | 0x20 | ASCII space, written %20 in URLs |
| 64 | 0x40 | A common CPU cache line size in bytes |
| 100 | 0x64 | ASCII "d" |
| 111 | 0x6F | ASCII "o" |
| 127 | 0x7F | Largest signed 8-bit value |
| 128 | 0x80 | A byte with only the high bit set |
| 142 | 0x8E | 8 × 16 + 14, so the low digit is E |
| 158 | 0x9E | 9 × 16 + 14, another E in the units place |
| 255 | 0xFF | Largest byte; a full channel in a hex color |
| 256 | 0x100 | Number of values one byte can hold |
| 384 | 0x180 | 1 × 256 + 8 × 16 + 0, so the digits read 180 |
| 729 | 0x2D9 | 3⁶, a classic classroom conversion exercise |
| 1,000 | 0x3E8 | Milliseconds in a second |
| 1,024 | 0x400 | 1 KiB |
| 4,096 | 0x1000 | 4 KiB, a common memory page size |
| 9,999 | 0x270F | Largest four-digit decimal number |
| 32,768 | 0x8000 | 2¹⁵, one past the largest signed 16-bit value |
| 50,000 | 0xC350 | Worked step by step in the section above |
| 65,535 | 0xFFFF | Largest unsigned 16-bit value; highest TCP/UDP port |
| 65,536 | 0x10000 | 64 KiB; number of values in 16 bits |
| 262,144 | 0x40000 | 256 KiB, a typical L2 cache size |
| 2,147,483,647 | 0x7FFFFFFF | Largest signed 32-bit integer |
| 4,294,967,295 | 0xFFFFFFFF | Largest unsigned 32-bit integer |
Frequently asked questions
How do I convert decimal to hexadecimal?
Divide by 16 repeatedly and collect the remainders, writing 10–15 as A–F, then read them in reverse. 175 ÷ 16 = 10 remainder 15, and 10 ÷ 16 = 0 remainder 10, so 175 is AF.
What is 255 in hex?
FF. It is the largest one-byte value, which is why color channels run from 00 to FF.
How do I convert RGB to a hex color?
Convert each channel to two hex digits and join them: rgb(255, 136, 0) is FF, 88 and 00, giving #FF8800.
How do I convert decimal to hex in code?
JavaScript: (500).toString(16) returns "1f4". Python: hex(500) returns '0x1f4', or format(500, "X") for "1F4".
What is the formula for decimal to hexadecimal conversion?
Repeated division by 16: divide the number by 16, write down the remainder as a hex digit (10–15 become A–F), divide the quotient again, and stop at 0. The remainders read from last to first give the answer. For 255: 15 r15 (F), then 0 r15 (F), so FF.
What is 16 in hex?
10, written 0x10 in code. Hex digits run 0–9 and then A–F, so 10 is A and 15 is F, and 16 starts a new place: 1×16 + 0. Other common values: 32 = 20, 64 = 40, 100 = 64, 128 = 80, 255 = FF, 256 = 100 and 1000 = 3E8.
What is 1000 in hex?
1000 in decimal is 3E8 in hex: 3 × 256 + 14 × 16 + 8 = 1000.
What is 4096 in hex?
4096 in decimal is 1000 in hex, because 4096 = 16³.
How do I convert decimal to hex in Excel?
Use =DEC2HEX(A1) to convert the number in cell A1, so 255 gives FF. Add a second argument to pad the result with leading zeros: =DEC2HEX(255, 4) returns 00FF, which keeps a column of hex values the same width.
How is a negative decimal number written in hex?
Negative numbers use two's complement. −2 is FE as an 8-bit value and FFFFFFFE as a 32-bit value. This converter keeps the minus sign instead and shows −2 as -2.
How do I convert denary to hexadecimal?
Divide by 16 and note each remainder until the quotient is 0, then read the remainders from the last to the first, writing 10 to 15 as A to F. For 729: 729 ÷ 16 = 45 remainder 9, 45 ÷ 16 = 2 remainder 13 (D) and 2 ÷ 16 = 0 remainder 2, so 729 is 2D9.
What is -1 in hex?
It depends on the width. In two's complement, −1 has every bit set, so it is FF as an 8-bit value, FFFF in 16 bits and FFFFFFFF in 32 bits. This converter writes it as -1, keeping the sign, because it converts whole numbers rather than fixed-width integers.
How do I convert a decimal fraction such as 3.14159 to hex?
Convert the whole part as usual, then multiply the fractional part by 16 again and again, taking the whole-number part each time as the next hex digit. For 0.14159: × 16 = 2.27 gives 2, 0.27 × 16 = 4.25 gives 4, then 3 and F, so 3.14159 is about 3.243F in hex. This converter handles whole numbers only, so do the fraction by hand or with float.hex() in Python.
What is 256 KB in hex?
256 KB of memory is 256 × 1024 = 262,144 bytes, which is 0x40000 in hex. Sizes that are powers of two always come out as a single digit followed by zeros, which is why buffer and page sizes are usually written in hex.