Binary Calculations and Decimal Conversion

Jul 10, 2024

Binary Calculations and Decimal Conversion

Binary Basics

  • Binary System: Uses two different numbers - 0 and 1.
  • Bits: Each 0 or 1 in binary is a bit.
  • Bytes and Octets: 8 bits form a byte, also called an octet.

Creating a Conversion Chart

  • Create a chart from right to left, doubling each time:
    • 1, 2, 4, 8, 16, 32, 64, 128
  • This chart helps in converting binary to decimal and vice versa.
  • Extendable beyond 128 (256, 512, etc.) for larger numbers.

Converting Binary to Decimal

  1. Write the binary number.
  2. Layer the conversion chart on top.
  3. Bring down numbers where bits are 1, keep zeros otherwise.
  4. Add the numbers corresponding to 1s.

Example Conversions

  • Binary: 00000010
    • Chart values: 1, 2, 4, 8, 16, 32, 64, 128
    • Result: 2
  • Binary: 10000010
    • Chart values: 128, 64, 32, 16, 8, 4, 2, 1
    • Result: 130
  • Binary: 11111111
    • Chart values: 128, 64, 32, 16, 8, 4, 2, 1
    • Result: 255

Converting Decimal to Binary

  1. Write the decimal number.
  2. Layer the conversion chart.
  3. Place 1 or 0 in each column starting from highest, based on comparison.

Example Conversion

  • Decimal: 154
    • Chart: 128, 64, 32, 16, 8, 4, 2, 1
    • Steps:
      • 128 <= 154 → 1
      • 64: 192 > 154 → 0
      • 32: 160 > 154 → 0
      • 16: 144 <= 154 → 1
      • 8: 152 <= 154 → 1
      • 4: 156 > 154 → 0
      • 2: 154 <= 154 → 1
      • 1: Not needed → 0
    • Result: 10011010

Binary to Decimal Conversion Range

  • With 8 bits: Convert any number from 0 to 255.
  • More bits increase range:
    • 2 bits: 4 outcomes (0-3)
    • 3 bits: 8 outcomes (0-7)
    • 4 bits: 16 outcomes (0-15)
    • 5 bits: 32 outcomes (0-31)
    • 6 bits: 64 outcomes (0-63)
    • 7 bits: 128 outcomes (0-127)
    • 9+ bits: Increases total possible decimal values.

Powers of Two

  • Conversion relies on powers of two:
    • 2^0 = 1
    • 2^1 = 2
    • 2^2 = 4
    • 2^3 = 8
    • And so on...