Decimal to Hex

Convert decimal to hex (base 16) instantly, with uppercase digits ready for code or CSS colours. Exact for very large numbers; no 0x prefix added.

Runs in your browser. Files never leave your device.
Whole numbers of any size. Negative numbers keep a minus sign (not two's complement); fractions aren't supported.
Result (Hexadecimal (base-16))
FF

About the Decimal to Hex

Type any base-10 whole number and watch it turn into hexadecimal (base 16) as you go. Web designers need hex for colour channel values; developers meet it in memory addresses, Unicode code points and error codes. Students can check base 10 to base 16 exercises here without long division on paper.

Hex digits come out in capitals with no 0x prefix, ready to paste into CSS, code or a datasheet. Numbers of any practical size are converted exactly, including values well past the 64-bit range.

How it works

Hexadecimal has sixteen digits: 0 to 9 and then A, B, C, D, E and F for ten to fifteen. To convert, divide the decimal number by 16 and keep the remainder as a hex digit, then divide the quotient by 16 again, and so on until nothing is left. Reading the remainders from last to first gives the hex number.

The tool runs that loop on exact big integers, so there is no rounding at any size. Because 16 is 2⁴, every hex digit stands for exactly four binary bits, which is why programmers prefer hex as a compact way to write binary data.

repeat while n > 0:
  digit = n mod 16        (10→A, 11→B, 12→C, 13→D, 14→E, 15→F)
  n     = floor(n ÷ 16)
hex = digits in reverse order

Assumptions and limits

  • Whole numbers only: 3.5 and 1e6 are refused rather than rounded. Thousands separators such as 16,777,215 are accepted.
  • Negative input keeps its sign (−255 gives −FF). It does not produce a two's complement value like FFFFFF01.
  • There is no zero padding, so 10 converts to A, not 0A. CSS colours need two digits per channel, so add the leading 0 yourself for values under 16.
  • One number is converted at a time. For an RGB colour, convert red, green and blue separately and join the three pairs.

Worked examples

Convert decimal 1000 to hex

Three divisions bring it to zero. 1000 ÷ 16 = 62 remainder 8, 62 ÷ 16 = 3 remainder 14 (E), and 3 ÷ 16 = 0 remainder 3. Read upwards: 3E8.

1000 ÷ 16 = 62  r 8
  62 ÷ 16 =  3  r 14 → E
   3 ÷ 16 =  0  r 3
→ 3E8   (check: 3×256 + 14×16 + 8 = 1000)

RGB colour 255, 165, 0 to a hex colour code

Convert each channel: 255 gives FF, 165 gives A5 and 0 gives 0, which you pad to 00. Joined together the colour is #FFA500, the CSS named colour orange.

A Unicode code point

The euro sign is character number 8364. Converting it gives 20AC, so in HTML it can be written as € and in JavaScript as \u20AC.

Decimal and hexadecimal equivalents

Values a developer or designer meets often. Read left to right for decimal to hex, or right to left for hex back to decimal; the hex column has no 0x prefix, matching the converter's output.

DecimalHexWhere you see it
10Afirst letter digit
15Flargest single digit
1610one sixteen, no units
261A
422A
10064
1277Ftop of 7-bit ASCII
12880
200C8
255FFmax colour channel
256100
1024400one kibibyte
40961000a common page size
65535FFFF16-bit maximum
6553610000
16777215FFFFFFwhite, #FFFFFF
3735928559DEADBEEFa well-known debug marker

How to use the Decimal to Hex

  1. Enter the decimal value. Replace the starting 255 with the number you want, with or without thousands commas.
  2. Read the hex result. The base-16 answer appears in capital letters, or a note explains why the input can't be converted.
  3. Copy and use it. Copy Result puts the digits on your clipboard; add 0x or # in front if your code or stylesheet expects it.

Frequently asked questions

What is 255 in hexadecimal?

FF. 255 is 15 × 16 + 15, and fifteen is written F, so both digits are F. It's the largest value one byte can hold, which is why FF appears in colour codes like #FFFFFF.

How do I convert a decimal RGB colour to a hex code?

Convert red, green and blue one at a time, pad any single-digit result with a leading zero, then join the three pairs after a #. For 46, 139, 87 that gives 2E, 8B and 57, so #2E8B57 (sea green). A channel below 16, such as 9, converts to the single digit 9 and must be written 09.

Why does the result not start with 0x?

Because 0x isn't part of the number. It's a notation that tells a programming language the digits are hex. The tool gives the bare digits so they fit anywhere: add 0x for C, JavaScript or Python, or # for a CSS colour.

Can I convert negative numbers to hex?

Yes, but the answer keeps a minus sign, so −26 gives −1A. A program storing −26 in 32 bits would show the two's complement form FFFFFFE6; to get that, add 2³² (4294967296) to the negative number first and convert the result.

Are lowercase hex letters the same as uppercase?

Yes. A5 and a5 are the same value, 165. The converter writes capitals because they're easier to read next to digits, but CSS, HTML and nearly every programming language accept either case.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.