NumForge LogoNumForge
Explore
Radix Conversion6 min read

How to convert decimal to hexadecimal?

A step-by-step masterclass in base-10 to base-16 positional transformations, division algorithms, and 4-bit nibble mapping.

Overview

Converting decimal integers and fractions to hexadecimal is a foundational skill in systems programming, reverse engineering, and digital circuit design. This guide details both the successive division-by-16 method and the fast binary-intermediate method.

1. Understanding the Core Concept

Decimal (Base 10) is the standard human counting system using ten positional digits (0–9). Hexadecimal (Base 16) is a compact base utilizing sixteen unique alphanumeric symbols: digits 0 through 9 followed by letters A through F (where A=10, B=11, C=12, D=13, E=14, and F=15). In computer science and digital electronics, hexadecimal serves as human-friendly shorthand for binary strings because exactly one hex digit represents four binary bits (one nibble), and two hex digits perfectly align with one 8-bit byte.

2. How Does It Work? Step-by-Step Methodology

To convert a positive decimal integer into hexadecimal, apply the successive division by 16 algorithm: divide the integer by 16, record the integer quotient and the remainder, and continue dividing the resulting quotient until it reaches 0. If any remainder is between 10 and 15, convert it to its corresponding hex letter (10=A, 11=B, 12=C, 13=D, 14=E, 15=F). Finally, read the recorded remainders in reverse order—from the last division step (Most Significant Digit) to the first (Least Significant Digit). Alternatively, for mental math or quick validation, convert the decimal value into binary, pad to a multiple of 4 bits, and map each 4-bit block directly to its hex equivalent.

Mathematical AlgorithmFormal Method
Successive Division Algorithm: Q_0 = Decimal Number Q_1 = ⌊Q_0 ÷ 16⌋, R_0 = Q_0 mod 16 (Mapped to 0–9, A–F) Q_2 = ⌊Q_1 ÷ 16⌋, R_1 = Q_1 mod 16 ... Q_k = 0, R_{k-1} = Q_{k-1} mod 16 Hex Result = (R_{k-1} R_{k-2} ... R_1 R_0)_16 Positional Verification Check: N_10 = Σ (d_i × 16^i) for i = 0 to k-1
Worked Problem

3. Detailed Worked Example & Verification

Example Problem: Convert decimal 479 into hexadecimal. Step 1: Divide 479 by 16 479 ÷ 16 = 29 with remainder 15. Remainder 15 maps to hex digit 'F'. Step 2: Divide quotient 29 by 16 29 ÷ 16 = 1 with remainder 13. Remainder 13 maps to hex digit 'D'. Step 3: Divide quotient 1 by 16 1 ÷ 16 = 0 with remainder 1. Remainder 1 maps to hex digit '1'. Quotient is now 0. Terminate division. Read remainders from bottom to top (Step 3 to Step 1): Result: 479_10 = 1DF_16. Mathematical Proof / Verification: (1 × 16²) + (13 × 16¹) + (15 × 16⁰) = (1 × 256) + (13 × 16) + (15 × 1) = 256 + 208 + 15 = 479 (Matches original decimal integer).

4. Essential Rules & Edge Cases

  • Always replace remainders from 10 to 15 with letters A to F (10=A, 11=B, 12=C, 13=D, 14=E, 15=F).
  • Read the remainders from bottom to top (last remainder is the Most Significant Digit, first remainder is the Least Significant Digit).
  • For decimal fractions, multiply repeatedly by 16 and record the integer portion from top to bottom (e.g. 0.625 × 16 = 10.0 -> 0.A_16).
  • Zero in decimal is always represented as 0 in hexadecimal.
  • Negative decimals require either an explicit minus sign (-1DF_16) or fixed-width Two’s Complement representation.

5. Practical Engineering Applications

  • Memory Addressing: Microprocessor memory dumps and RAM pointer addresses (e.g., 0x7FFF_FFFF).
  • Web Colors: CSS hexadecimal color codes (#FFFFFF, #0066CC, #1D1D1F).
  • Network Protocols: IPv6 addresses (2001:0db8::) and MAC hardware addresses (00:1A:2B:3C:4D:5E).
  • Assembly & Disassembly: Machine opcode representations in x86, ARM, and RISC-V architectures.

6. Common Mistakes to Avoid

  • WarningWriting remainders greater than 9 as numbers instead of letters (e.g., writing 11315 instead of 1DF).
  • WarningReading remainders from top to bottom instead of bottom to top, producing inverted digit order (FD1 instead of 1DF).
  • WarningForgetting that 16⁰ equals 1 when verifying positional weights.
Interactive Verification

Try It in Your Browser (0ms Latency)

Validate these formulas instantly with NumForge's deterministic hardware-grade online tools.

FAQ

Frequently Asked Questions

Why do we divide by 16 when converting to hexadecimal?

Because hexadecimal is a positional base-16 number system. Dividing by 16 isolates the least significant digit as the integer remainder, while the quotient represents the higher powers of 16.

What are the hexadecimal letters and their decimal values?

A represents 10, B represents 11, C represents 12, D represents 13, E represents 14, and F represents 15.

How do you convert decimal fractions to hexadecimal?

Multiply the fractional part by 16 repeatedly. The integer part of each multiplication becomes the next hex digit after the radix point, read top to bottom.

More Learning Guides

View All 7 Guides →