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.
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:
- Divide 7531 by 16: quotient = 470, remainder = 11 (B)
- Divide 470 by 16: quotient = 29, remainder = 6
- Divide 29 by 16: quotient = 1, remainder = 13 (D)
- 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
Related Topics
Convert Hexadecimal to Decimal
Hexadecimal (Base 16) → Decimal (Base 10)
Convert Decimal to Binary
Decimal (Base 10) → Binary (Base 2)
Convert Decimal to Octal
Decimal (Base 10) → Octal (Base 8)
Understanding Hex Color Codes in CSS and Design
Visual Color → Hexadecimal (Base 16)
Convert Hex Color Codes to RGB
Hexadecimal (Base 16) → RGB (Decimal Triplet)