Aprelius logo
uptime: 00:00:00
Computer Science

Converting Number Systems

Converting between number and binary is straightforward after properly understating both. Each positional number system uses a base (radix) that determines the value of every digit position

  • Binary: base 2 (digits: 0-1)
  • Decimal: base 10 (digits: 0-9)
  • Hexadecimal: base 16 (digits: 0-9, A-F where A=10, B=11, C=12, D=13, E=14, F=15)

To convert to decimal, multiply each digit by the base raised to its position (counting from 0, right to left), then sum the results.

Base 10 (Decimal)

text
129 (decimal) = 1×10² + 2×10¹ + 9×10⁰
              = 1×100 + 2×10 + 9×1
              = 100 + 20 + 9
              = 129

Position:  [2] [1] [0]
Digit:     [1] [2] [9]

Base 2 (Binary)

text
10110101 (binary) = 1×2⁷ + 0×2⁶ + 1×2⁵ + 1×2⁴ + 0×2³ + 1×2² + 0×2¹ + 1×2⁰
                  = 1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 1×4 + 0×2 + 1×1
                  = 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1
                  = 181 (decimal)

Position:  [7] [6] [5] [4] [3] [2] [1] [0]
Digit:     [1] [0] [1] [1] [0] [1] [0] [1]

Base 16 (Hexadecimal)

text
0x2F (hex) = 2×16¹ + F×16⁰
           = 2×16 + 15×1
           = 32 + 15
           = 47 (decimal)

Position:  [1] [0]
Digit:     [2] [F]

---

0xA3C (hex) = A×16² + 3×16¹ + C×16⁰
            = 10×256 + 3×16 + 12×1
            = 2560 + 48 + 12
            = 2620 (decimal)

Position:  [2] [1] [0]
Digit:     [A] [3] [C]

Quick conversion tips

  • Decimal to Binary: repeatedly divide by 2, recording remainders in reverse order
  • Decimal to Hex: repeatedly divide by 16, recording remainders in reverse order
  • Binary to Hex: group binary digits into sets of 4 (each hex digit = 4 binary bits)
    • Example: 10110101 = 1011 0101 = 0xB5
  • Hex to Binary: convert each hex digit to 4 binary bits
    • Example: 0x2F = 0010 1111 = 00101111