Guide
How to convert decimal to hexadecimal step by step
Convert a decimal integer to hexadecimal by dividing by 16, interpreting remainders, and checking the exact result.
by Tools in a Tab · Published on · Updated
Short answer
To convert a decimal integer to hexadecimal, divide it repeatedly by 16,
record each remainder, and read the remainders from last to first. Remainders
0 through 9 keep their digits; 10, 11, 12, 13, 14, and 15
become A, B, C, D, E, and F.
To calculate your own value, open the
number base converter, choose decimal
as the input base, and paste the integer. To check a hexadecimal result in the
reverse direction, choose hexadecimal or include its 0x prefix.
Example: convert 254 to hexadecimal
Only two divisions are needed:
| Division | Quotient | Remainder | Hexadecimal digit |
|---|---|---|---|
254 ÷ 16 |
15 |
14 |
E |
15 ÷ 16 |
0 |
15 |
F |
Reading the remainders from bottom to top gives:
254 decimal = FE hexadecimal
The 0x prefix commonly declares the base, so 0xFE represents the same
value. Check it with the
IPv4 and number base converter, which
uses exact integer arithmetic even for values beyond JavaScript’s safe Number
range.
Why division by 16 works
Hexadecimal is a positional base-16 system. Each place has a power-of-16 weight:
FE = 15 × 16¹ + 14 × 16⁰
= 240 + 14
= 254
The same process works for every non-negative integer. For example, 4095
produces three remainders of 15, so its result is FFF. Zero is a direct
case: decimal 0 is hexadecimal 0.
Common mistakes
- Reading remainders in the order they were produced instead of reversing them.
- Writing decimal
15as two hexadecimal characters instead ofF. - Treating decimal
10and hexadecimal10as equal:0x10is decimal16. - Including visual separators as though they were digits.
- Applying two’s complement before choosing a bit width.
A negative mathematical value can keep its sign, such as -26 = -1A. That is
not a two’s-complement binary encoding. An 8-, 16-, or 32-bit width must be
chosen first because each produces a different pattern; the converter does not
guess that width.
Check the conversion
Reading the remainders forwards would give EF, but
14 × 16 + 15 = 239, not 254. Examples such as 255 → FF cannot reveal
this mistake because both digits are identical.
Try it: what is decimal 202 in hexadecimal?
202 ÷ 16 gives quotient 12 and remainder 10. Then 12 ÷ 16 gives quotient 0 and remainder 12. Reading backwards gives CA: 12 × 16 + 10 = 202. Reversing it to AC would give 172.
Convert the hexadecimal result back by multiplying each digit by its power of 16.
This reverse check catches misplaced remainders and incorrect digits. The
ECMAScript specification supports exact BigInt string representations with
an explicit radix from 2 through 36 in
BigInt.prototype.toString.