↑ ↓ to moveEnter to openEsc to close

Decimal to hex converter

Enter a whole number and get its hexadecimal form, with the divide-by-16 table that builds it digit by digit. Negative numbers are written in two’s complement at the width you pick.

  • Hex
  • Padded
  • Binary

Repeated division by 16

The division method

To write a decimal number in base 16, keep dividing by 16 and note the remainders. Each remainder (0 to 15) becomes one hex digit, written as 0–9 or A–F. Read them from the last division back to the first.

Example: 2019

DivisionQuotientRemainderHex digit
2019 ÷ 1612633
126 ÷ 16714E
7 ÷ 16077

Reading upward gives 7E3. You can check it the other way: 7 × 256 + 14 × 16 + 3 = 2,019.

The tool shows the same table for any whole number, however long. The arithmetic uses BigInt, so a 30-digit number converts exactly.

Second example: 2026

  • 2026 ÷ 16 = 126, remainder 10 → A
  • 126 ÷ 16 = 7, remainder 14 → E
  • 7 ÷ 16 = 0, remainder 7 → 7

So 2026 is 7EA. Next year's number differs from this year's only in the last hex digit, because both share the 126 quotient after the first step.

A shortcut for small numbers

For numbers under 256, you only need one division. Divide by 16: the whole part is the first digit and the remainder is the second. 200 ÷ 16 = 12 remainder 8, so 200 = C8. This is exactly what you do when converting an RGB channel to a HEX color pair. The RGB to HEX converter applies it to all three channels at once.

Negative numbers

There is no single "hex of −42". Computers store negatives in two's complement, which depends on how many bits the value occupies. Choose a width and the tool adds 2 to that power before converting:

WidthCalculationHex
8-bit−42 + 256 = 214D6
16-bit−42 + 65,536 = 65,494FFD6
32-bit−42 + 4,294,967,296 = 4,294,967,254FFFFFFD6

The wider forms just add F digits on the left, which is called sign extension. If a number is too negative for the width (below −128 for 8 bits, say), the tool warns you rather than wrapping silently.

Output options

  • Hex: the shortest form, such as 0x7E3.
  • Padded: rounded up to whole bytes (0x07E3), or the full width of F digits for negatives. This is the form you'll usually want for byte-oriented work such as packets, file headers or color channels.
  • Binary: the same value in base 2, grouped in fours. Each group corresponds to one hex digit.

Untick 0x prefix if you're pasting into a context that doesn't want it, such as a CSS color or a spreadsheet HEX2DEC formula.

Accepted input

Whole numbers only, with an optional minus sign. Commas, spaces and underscores used as thousands separators are ignored, so 1,000,000 and 1_000_000 both work. Decimals like 3.5 are rejected. Fractional hex exists, but almost nothing outside textbooks uses it, and floating-point values have their own format (IEEE 754) that this tool doesn't cover.

Common uses

  • writing color channels as HEX for CSS;
  • setting a register or bit mask from a decimal value in a datasheet;
  • converting a Unicode code point, such as 9731 for ☃, to the U+2603 form;
  • encoding numeric IDs compactly in URLs or filenames.

To go back, use hex to decimal, which also reads two's complement. For sums and bitwise logic, open the hex calculator. If you need the binary view in more detail, the binary to hex page shows the grouping.

FAQ

How do I convert in Excel or Google Sheets?

Use =DEC2HEX(2019), which returns 7E3. Excel's version handles values up to 549,755,813,887 and uses 10-digit two's complement for negatives.

How do I convert in code?

In JavaScript, (2019).toString(16). In Python, hex(2019) or format(2019, 'X'). In C, printf("%X", 2019).

Why are letters used as digits?

Base 16 needs sixteen symbols and our number system only has ten. Using A to F for 10 to 15 became standard with IBM's System/360 in the 1960s.