Skip to content
AgileLogics

Decimal to Hex

Converts a base-10 (decimal) number into its base-16 (hexadecimal) equivalent.

How it works

Enter a whole number (e.g. 255) and click Convert.

How do you convert decimal to hex?

Divide the decimal number by 16, write down the remainder, and repeat with the quotient until it reaches 0. Remainders of 10 to 15 become the letters a to f. Reading the remainders from last to first gives the hexadecimal number. For 2024, the remainders are 8, 14 and 7, so 2024 in hex is 7e8.

Hex is base 16, and each hex digit covers exactly four bits. That's why it shows up wherever people need to read binary data: color codes, memory addresses, byte values and error codes.

Quick use

  1. Enter a whole number, for example 48879.
  2. Click Convert.
  3. The result appears in lowercase without a prefix: beef.

Worked example: 2024

Step Division Quotient Remainder Hex digit
1 2024 ÷ 16 126 8 8
2 126 ÷ 16 7 14 e
3 7 ÷ 16 0 7 7

Bottom to top: 7e8. To check, expand it: 7 × 256 + 14 × 16 + 8 = 1792 + 224 + 8 = 2024.

Building CSS colors from decimal channels

The #rrggbb color syntax in CSS Color Module Level 4 is three decimal channels, each written as exactly two hex digits. Convert one channel at a time:

Channel Decimal Tool output Use in the color
Red 30 1e 1e
Green 144 90 90
Blue 255 ff ff

That gives #1e90ff. The trap is small values. This tool prints the shortest form, so 9 comes out as 9 and 0 as 0. In a color they must be 09 and 00, otherwise rgb(9, 128, 16) would become a broken five-digit #98010 instead of #098010. If you're converting colors often, the RGB to HEX converter handles all three channels and the padding in one go.

Memory sizes and addresses

Programmers convert decimal to hex mostly to line numbers up with how hardware counts. Round binary sizes look tidy in hex and messy in decimal:

Decimal Hex Where you see it
255 ff Largest byte value
4096 1000 A common memory page size (4 KiB)
65535 ffff Largest 16-bit value
4294967295 ffffffff Largest 32-bit value, the top of a 32-bit address space
3405691582 cafebabe The magic number at the start of every Java class file

The last row is a fun one. The Java Virtual Machine Specification defines a class file's first four bytes as 0xCAFEBABE, and decoders print it in decimal as 3405691582. Converting it back to hex makes the pattern obvious.

When a conversion fails

Input What you see What to do
1,000 Enter a valid decimal number... Remove thousands separators
1e3 Same error Write it out: 1000
-1 Same error Negative values aren't supported; for a 32-bit two's complement value add 4294967296 first, so -1 becomes 4294967295, which is ffffffff
3.75 Same error Only integers; see the IEEE-754 tool for fractional values
9007199254740992 or larger That number is too large to convert precisely. Above 2^53 - 1 JavaScript can't hold every integer exactly

That last limit is real, not arbitrary. JavaScript numbers are 64-bit floats, and Number.MAX_SAFE_INTEGER is the ceiling for exact integer arithmetic. Refusing larger input is better than printing a hex value whose last digits are quietly wrong.

Related tools

  • Hex to decimal reverses this conversion, for example when you're reading an address from a crash log.
  • Decimal to binary shows the individual bits behind each hex digit.
  • The color picker lets you choose a color visually and copy the hex code.

Last updated

Frequently asked questions

How do you convert decimal to hexadecimal?
Divide by 16 and keep the remainder, writing 10 to 15 as a to f. Repeat with the quotient until it is 0, then read the remainders bottom to top. 2024 gives remainders 8, 14 (e) and 7, so the answer is 7e8.
How do I build a CSS hex color from RGB numbers?
Convert each channel (0 to 255) separately and pad each result to two digits. rgb(30, 144, 255) gives 1e, 90 and ff, so the color is #1e90ff. Watch for small values: 9 converts to 9, which you must write as 09.
Does the output include 0x or use capital letters?
Neither. 255 prints as ff. Add 0x for source code, or # for a CSS color, and switch to capitals if your codebase prefers them; hex digits are case-insensitive.
What numbers can it convert?
Non-negative whole numbers from 0 to 9007199254740991 (which is 1fffffffffffff in hex). Negative numbers, decimals, commas and scientific notation like 1e3 are rejected with "Enter a valid decimal number".