Convert Decimal to Hexadecimal

Convert decimal numbers to hexadecimal using repeated division by 16. Includes worked examples, remainder mapping to A-F, and useful programming shortcuts.

Decimal (Base 10)Hexadecimal (Base 16)Conversion

Detailed Explanation

Converting decimal to hexadecimal uses the same approach as decimal to binary, but you divide by 16 instead of 2. After each division, remainders from 10-15 are written as letters A-F.

Step-by-step example — converting 7531 to hexadecimal:

  1. Divide 7531 by 16: quotient = 470, remainder = 11 (B)
  2. Divide 470 by 16: quotient = 29, remainder = 6
  3. Divide 29 by 16: quotient = 1, remainder = 13 (D)
  4. Divide 1 by 16: quotient = 0, remainder = 1

Read remainders bottom to top: 1D6B. So 7531₁₀ = 0x1D6B.

Quick conversion tips:

For small numbers, it helps to memorize key values. The hex digits for 0-15 correspond to 0-9 then A-F. For multiples of 16, the conversions are clean: 16=0x10, 32=0x20, 48=0x30, and so on. Numbers like 255 convert to 0xFF because 255 = 15x16 + 15.

The remainder-to-hex mapping:

Remainder Hex Digit
0-9 0-9
10 A
11 B
12 C
13 D
14 E
15 F

Verification in code:

In JavaScript, use (7531).toString(16) which returns "1d6b". In Python, hex(7531) returns "0x1d6b". Note that most programming languages produce lowercase hex letters by default. The case does not affect the value.

Decimal-to-hex conversion is essential when setting memory addresses, defining color values in CSS, writing hardware register values, and encoding binary data in a human-readable format. It is one of the most frequently used conversions in software development and systems programming.

Use Case

Front-end developers convert decimal RGB values (like 65, 105, 225) to hexadecimal to construct CSS color codes such as #4169E1 for Royal Blue.

Try It — Number Base Converter

Open full tool