The Division-by-16 Remainder Algorithm
Converting decimal integers to hexadecimal requires extracting remainders through repeated division by 16:
- Divide the decimal number by 16. Record the integer quotient and the remainder.
- If the remainder is between 10 and 15, convert it to its hex letter (10=A, 11=B, ..., 15=F).
- Take the quotient from the previous step and divide by 16 again.
- Repeat until the quotient becomes 0.
- Read the sequence of remainders from bottom to top (last remainder is the first hex digit).
Detailed Walkthrough: Converting Decimal 759
- Step 1: 759 ÷ 16 = 47, with remainder 7.
- Step 2: 47 ÷ 16 = 2, with remainder 15 (which is F).
- Step 3: 2 ÷ 16 = 0, with remainder 2. Quotient is 0, so stop.
Reading the remainders from bottom to top yields: 2, F, 7 → 0x2F7.