Decimal to Hexadecimal Converter

Convert a decimal number to its hexadecimal and binary representation.

Supports 2–20-bit signed representations with two's complement for negative values.

Updated August 12, 2026
Frank Zhao - Creator
CreatorFrank Zhao
Loading calculator…

Introduction / overview

Decimal to Hexadecimal Converter turns any whole decimal number into its hexadecimal equivalent — and, because every four binary digits collapse into a single hex digit, it also shows the binary value grouped into nibbles so 00000000000011000000000000001100 reads as 0000 0000 0000 11000000\ 0000\ 0000\ 1100 instead of a wall of digits.

Negative values are handled with two’s complement, and the conversion is an exact integer operation — nothing is rounded. By default the tool works in a 16-bit representation, and you can switch to any width from 2 to 20 bits.

It is the tool to reach for when you are reading a hex value from code, an address, a color, a register dump, or a network trace, and you need to know what decimal value sits behind it. Programmers, students, and anyone learning how computers store integers all end up converting decimal to hex sooner or later.

How to use / quick start

1

Enter a whole decimal number

Type the value into the Decimal field. The input domain shown above the field (for example −32,768 to 32,767 at the default 16 bits) tells you what fits in the current representation. Whole numbers only — decimals and fractions are not converted.

2

Read the Binary and Hexadecimal results

The Binary row shows the value padded to the selected bit width and grouped in blocks of four; the Hexadecimal row shows the uppercase hex form you can copy straight into code or documentation.

3

Change the bit width when you need to

Turn on Change the binary representation to pick a preset — 4, 8, 12, or 16 bits — or choose Other and type any width from 2 to 20. A wider representation accepts a wider range of values.

Example — convert 4987 to hex

Type 49874987 in the Decimal field. Repeating the “divide by 16, keep the remainder” step from the bottom up:

4987÷16=311 r 114987 \div 16 = 311\ \text{r}\ 11311÷16=19 r 7311 \div 16 = 19\ \text{r}\ 719÷16=1 r 319 \div 16 = 1\ \text{r}\ 31÷16=0 r 11 \div 16 = 0\ \text{r}\ 1

Reading the remainders from last to first gives 137B16137B_{16}. The tool shows Binary: 0001 0011 0111 1011 and Hexadecimal: 137B at the default 16-bit width.

Calculation method

For a non-negative value, the binary representation is just the usual place-value encoding padded with leading zeros to the chosen width. For a negative value, the tool uses two’s complement: it adds 2n2^n to the number, then encodes that result in nn bits.

B=N, for N0B = N,\ \text{for } N \ge 0B=N+2n, for N<0\qquad B = N + 2^n,\ \text{for } N < 0

The hexadecimal result is produced from the same encoded value: starting from the right, the bits are split into groups of four (nibbles), and each group maps to a single hex digit.

H=k=0m1hk16k,hk=8b4k+3+4b4k+2+2b4k+1+b4kH = \sum_{k=0}^{m-1} h_k \cdot 16^{k},\qquad h_k = 8 b_{4k+3} + 4 b_{4k+2} + 2 b_{4k+1} + b_{4k}

Worked example — negative value

For 87-87 at 16 bits, the encoded value is 87+216=65449-87 + 2^{16} = 65449, which is 1111 1111 1010 10011111\ 1111\ 1010\ 1001 in binary:

87-87  \ \to\ 1111 1111 1010 100121111\ 1111\ 1010\ 1001_2  \ \to\ FFA916\mathrm{FFA9}_{16}

Every negative value therefore starts with a run of 11 bits — that leading F\mathrm{F} nibble is the two’s-complement “sign marker”, not a large number.

Variables

  • NN — the decimal input value
  • BB — the encoded value held in nn bits
  • nn — the bit width (2–20)
  • hkh_k — the kk-th hex digit (0–9, A–F)
  • bib_i — the bit at position ii (0 or 1)

Conversion is one-directional: the Binary and Hexadecimal rows are read-only results derived from the Decimal input. If you already have a hexadecimal value and want its decimal form, use the binary to hexadecimal converter, which converts both ways.

Frequently asked questions

Why is −1 shown as FFFF at 16 bits?

Because two’s complement encodes 1-1 as 1+216=65535-1 + 2^{16} = 65535, which is 1111 1111 1111 11111111\ 1111\ 1111\ 1111 in binary — and FFFF\mathrm{FFFF} in hex. The leading run of 11s is the sign marker; the same pattern would mean 6553565535 only if interpreted as unsigned.

Why do I see “Your data input exceeds the allowed limits”?

The number is too large (or too negative) for the current bit width. For example, at 8 bits the largest value is 127127, so 300300 is rejected. Turn on Change the binary representation and pick a wider width — the input domain note updates immediately to show the new range.

Why does the binary result start with so many zeros?

The value is padded to fill the selected bit width, then grouped into nibbles. At 16 bits, 1212 becomes 0000 0000 0000 11000000\ 0000\ 0000\ 1100. The leading zeros are part of the fixed-width representation and do not change the value.

Can I convert hexadecimal back to decimal here?

Not on this page — the output is read-only and the conversion is one-directional. To go the other way, or to convert between binary and hexadecimal directly, use the binary to hexadecimal converter.

Limitations

This calculator accepts whole decimal numbers only — a decimal point or fraction produces an “Enter a whole number.” message and nothing is converted. The bit width is limited to 2–20 bits, with 16 bits as the default. Negative values are interpreted as signed two’s complement, so the same input produces different binary and hex output at different widths, and numbers outside the current width’s range are not converted until you widen the representation. There is no hex-to-decimal direction on this page.

Decimal to Hexadecimal Converter - Convert Base-10 to Base-16