💾

Understanding Data Representation and Compression

Apr 23, 2025

1. Data Representation

Number Systems

Using Binary to Represent Data in a Computer System

  • Why Computers Use Binary:
    • Data must be converted to binary for processing.
    • Logic gates, switches, transistors process data in two states: high-low / on-off / 1 and 0.
    • Data is stored in registers.
  • How Binary Represents Data:
    • Binary value assigned to each character/pixel.

Binary Number System

  • Base: 2
  • Values: 0, 1
  • Units Increase: Powers of 2 (e.g., 2^0, 2^1)
  • Related Systems:
    • Denary (Base 10): Values 0-9
    • Hexadecimal (Base 16): Values 0-9, A-F

Conversions

  • Denary to Binary:
    • Use powers of 2, write 1 if power is ≤ number.
    • Check by adding powers with 1.
  • Binary to Denary:
    • Add up power values with binary digit 1.
  • Binary to Hexadecimal:
    • Group binary digits into nibbles, convert to hex.
  • Hexadecimal to Binary:
    • Convert each hex digit to binary.
  • Denary to Hexadecimal: Convert via binary.
  • Hexadecimal to Denary: Convert via binary.

Binary Addition

  • Addition rules:
    • 0+0=0,
    • 0+1=1,
    • 1+1=10 (carry 1),
    • 1+1+1=11 (carry 1)
  • Overflow:
    • Occurs when calculation exceeds register limit.

Binary Shifts

  • Left Shift: Multiplies by power of 2.
  • Right Shift: Divides by power of 2.
  • Effect: Bits lost at one end, zeros added at the other.

Two's Complement

  • Method for representing signed integers.
  • Conversion for Negatives:
    • Binary of positive equivalent,
    • Invert bits,
    • Add 1.

Benefits of Hexadecimal

  • Easier/quicker to read and debug than binary.
  • Uses fewer digits.
  • Applications: IP, MAC addresses, error codes, HTML colors.

Text, Sound, Images

Representing Text

  • Text converted to binary for computer processing.
  • Character Sets:
    • ASCII: 7-bit binary code.
    • Unicode: Variable-length, more characters and languages.

Representing Sound

  • Sound is an analog signal sampled for binary conversion.
  • Quality Factors:
    • Sample rate (samples per second).
    • Sample resolution (bits per sample).

Representing Images

  • Image made of pixels, each with a binary code.
  • Quality Factors:
    • Resolution (pixels dimensions).
    • Color depth (bits per color).

Data Storage

  • Units: Byte, Kibibyte, Mebibyte, etc.
  • File Size Calculation:
    • Images: resolution x color depth.
    • Sound: sample rate x resolution x time.

Data Compression

Purpose

  • Reduce file size, bandwidth, transmission time.

Lossy Compression

  • Removes data permanently.
  • Reduces file size.

Lossless Compression

  • No data loss.
  • Original file can be restored.

Applications

  • Lossy: Media files.
  • Lossless: Text, code files.