Base Conversions: Decimal, Binary, Octal, Hex
Jump to navigation
Jump to search
Base Conversions: Decimal, Binary, Octal, Hex
This page explains how to convert numbers between the most important bases: decimal (10), binary (2), octal (8), and hexadecimal (16).
General method: from any base to decimal
To convert from another base into decimal, expand the number into positional values.
Example: 725₈ = 7 × 8² + 2 × 8¹ + 5 × 8⁰ = 7 × 64 + 2 × 8 + 5 × 1 = 448 + 16 + 5 = 469₁₀.
General method: from decimal to another base
Use repeated division by the target base:
- Divide the number by the base.
- Record the remainder.
- Continue dividing the quotient until 0.
- Read the remainders backwards.
Example: Convert 232622₁₀ to octal
232622 ÷ 8 = 29077 remainder 6
29077 ÷ 8 = 3634 remainder 5
3634 ÷ 8 = 454 remainder 2
454 ÷ 8 = 56 remainder 6
56 ÷ 8 = 7 remainder 0
7 ÷ 8 = 0 remainder 7
Result: 706256₈.
Binary and octal
Binary and octal map directly:
- Each octal digit = 3 binary digits.
- Group binary digits into groups of 3 to convert to octal.
- Expand octal digits into 3-bit groups to convert to binary.
Example: 110110₂ → group 110 110 → 66₈.
Binary and hexadecimal
Binary and hexadecimal map directly:
- Each hex digit = 4 binary digits.
- Group binary digits into groups of 4 to convert to hex.
- Expand hex digits into 4-bit groups to convert to binary.
Example: 111100111101₂ → group 1111 0011 1101 → F3D₁₆.
Octal and hexadecimal
Convert through binary:
- Octal → binary (3 bits per digit).
- Regroup binary into 4 bits.
- Binary → hex.
Example: 157₈ → 1 = 001, 5 = 101, 7 = 111 → 001101111₂. Group as 0001 1011 11 → 1B7₁₆.
Practice examples
Decimal to binary: 37
37 ÷ 2 = 18 remainder 1
18 ÷ 2 = 9 remainder 0
9 ÷ 2 = 4 remainder 1
4 ÷ 2 = 2 remainder 0
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Read backwards: 100101₂.
Decimal to hex: 988664
988664 ÷ 16 = 61791 remainder 8
61791 ÷ 16 = 3861 remainder 15 (F)
3861 ÷ 16 = 241 remainder 5
241 ÷ 16 = 15 remainder 1
15 ÷ 16 = 0 remainder 15 (F)
Result: F15F8₁₆ = 0xF15F8.
Why conversions matter
- Binary is closest to hardware but unreadable in long form.
- Octal and hex are compact and map cleanly to binary.
- Decimal is human-friendly.
- Conversions are essential for reading memory dumps, debugging, and low-level programming.