Comprehensive Study Notes on Data Representation and Compression

Lesson 1: Fundamentals of Representation
  • Representation Basics

    • Representation relies on agreed-upon systems of symbols (e.g., alphabet, musical notes, mathematical symbols).

    • Computers store programs, text, numbers, images, and audio purely as numerical representations.

  • Data vs. Instructions

    • Data: Raw values or operands passed into the computer (e.g., numbers, text strings).

    • Instructions: Commands or operations executed on that data (e.g., add, multiply, save).

  • Binary & Electronic Circuits

    • Computers utilize electrical circuits made of microscopic electronic switches called transistors (approximately 7 nm7\,\text{nm} in size).

    • Each transistor exists in one of two physical states: ON (current flowing, represented by 11) or OFF (no current, represented by 00).

    • Any system with two distinct states is referred to as binary.

    • Increasing the number of binary switches increases the number of representable states: nn bits yield 2n2^n unique combinations.


Lesson 2: Number Bases and Conversions
  • Number Base Systems

    • Decimal (Base-10): Uses 1010 unique digits (00 through 99). Place values increase by powers of 1010 from right to left (11, 1010, 100100, 10001000, etc.).

    • Binary (Base-2): Uses 22 unique digits (00 and 11). Place values increase by powers of 22 from right to left (11, 22, 44, 88, 1616, 3232, 6464, 128128, etc.).

    • Base notation is expressed using subscript numbers (e.g., 1012101_2 indicates binary, while 10110101_{10} indicates decimal).

  • Conversions Between Binary and Decimal

    • Binary to Decimal: Write down the 8-bit place value grid (128,64,32,16,8,4,2,1128, 64, 32, 16, 8, 4, 2, 1), insert the binary digits, and sum all values that align with a 11.

    • Decimal to Binary: Compare the decimal value against the binary place values from left to right. If the place value is less than or equal to the remaining number, place a 11 in that column and subtract the place value; otherwise, record a 00.


Lesson 3: Binary Addition
  • The Four Golden Rules of Binary Addition

    • 0+0=00 + 0 = 0

    • 0+1=10 + 1 = 1

    • 1+1=1021 + 1 = 10_2 (00 written down, carry 11 to the left)

    • 1+1+1=1121 + 1 + 1 = 11_2 (11 written down, carry 11 to the left)

  • Method for Adding Numbers

    • Align bits in vertical columns starting from the least significant bit (rightmost).

    • Apply addition rules column-by-column, adding carried bits into the subsequent higher place value.


Lesson 4: Binary Subtraction
  • The Four Golden Rules of Binary Subtraction

    • 0−0=00 - 0 = 0

    • 1−1=01 - 1 = 0

    • 1−0=11 - 0 = 1

    • 0−1=10 - 1 = 1 (requires borrowing 11 from the next column to the left)

  • Borrowing Mechanics

    • A borrowed 11 from the adjacent left column has a place value equivalent to two 11s in the current column (210−110=1102_{10} - 1_{10} = 1_{10}).

    • If the adjacent column contains a 00, traverse leftward until a 11 is encountered, decompose each intermediary column, and carry through to the target bit.


Lesson 5: Binary Shifts, Overflow, and Underflow
  • Binary Shifts

    • Left Shift (Multiplication): Shifting bits left multiplies the value. Shifting left by 11 space multiplies by 22; shifting left by 22 spaces multiplies by 44 (222^2); shifting left by nn spaces multiplies by 2n2^n. Vacated positions on the right are padded with 00.

    • Right Shift (Division): Shifting bits right divides the integer value by 2n2^n. In integer arithmetic, bits shifted past the units column are discarded (truncated).

  • Arithmetic Errors

    • Overflow: Occurs when the result of a calculation exceeds the maximum value that the allocated number of bits can store (e.g., adding 11 to an 8-bit limit of 255255 generates a 9th bit that is lost, wrapping the output to 00).

    • Underflow: Occurs when a value is too small to be represented in the allocated precision (such as fractional bits shifted off the right side during division of real numbers).


Lesson 6: Signed Binary Integers
  • Signed vs. Unsigned Integers

    • Unsigned Integers: Represent only positive values and zero.

    • Signed Integers: Represent positive and negative whole numbers using the Most Significant Bit (MSB) as the sign indicator (00 for positive, 11 for negative).

  • Sign and Magnitude

    • The MSB specifies the sign (0=+0 = +, 1=−1 = -), while the remaining bits designate the magnitude (absolute numerical size).

    • In an 8-bit system, 11 bit is allocated for the sign and 77 bits are left for magnitude (00 to 127127).

  • Two’s Complement

    • The standard approach used by computer systems. The MSB carries a negative place value (e.g., an 8-bit grid has place values: −128,64,32,16,8,4,2,1-128, 64, 32, 16, 8, 4, 2, 1).

    • Converting a Negative Decimal to Two’s Complement:

    1. Write the positive decimal number in binary.

    2. Invert (flip) all the bits (0→10 \rightarrow 1, 1→01 \rightarrow 0).

    3. Add 11 to the inverted binary pattern.


Lesson 7: Hexadecimal Representation
  • Hexadecimal Properties (Base-16)

    • Comprises 1616 symbols: digits 0−90-9 and letters A−FA-F (A=10A=10, B=11B=11, C=12C=12, D=13D=13, E=14E=14, F=15F=15).

    • Used because it provides a human-readable shorthand for binary, drastically shortens bit strings, and minimizes transcription errors.

    • Applications include HTML/CSS colour codes (e.g., #B827EB), MAC addresses, and memory dump debugging screens.

  • Hexadecimal Conversions

    • Each hexadecimal digit represents exactly 44 bits (11 nibble).

    • Two hexadecimal digits equal 88 bits (11 byte).

    • Binary to Hex: Split the binary byte into two separate 4-bit nibbles, convert each nibble to decimal (8−4−2−18-4-2-1), and write the corresponding hex symbol.


Lessons 8 & 9: Character Sets (ASCII & Unicode)
  • Character Sets Overview

    • A defined list of characters recognized by computer hardware and software, paired with unique binary codes.

    • Characters are arranged logically and sequentially (e.g., uppercase letters, lowercase letters, and digits form continuous numerical blocks).

  • ASCII (American Standard Code for Information Interchange)

    • Originally standard 7-bit ASCII (27=1282^7 = 128 unique characters).

    • Extended ASCII uses 8 bits (11 byte per character, yielding 28=2562^8 = 256 combinations).

    • Limited to standard Latin letters, numbers, and basic punctuation; incapable of supporting non-English languages, emojis, or specialized symbols.

  • Unicode

    • Extends text encoding using variable lengths up to 3232 bits (44 bytes per character), accommodating over 4 billion4\,\text{billion} potential patterns (140,000+140,000+ currently assigned).

    • Backwards-compatible with 7-bit ASCII (character codes 00 through 127127 are identical).

  • Text File Size Formula
      File Size (bytes)=Number of characters×Bytes per character\text{File Size (bytes)} = \text{Number of characters} \times \text{Bytes per character}


Lessons 10 & 11: Bitmap Images & Size Calculations
  • Bitmap Construction

    • Images constructed from a grid of individual picture elements called pixels.

    • Colour Depth (Bit Depth): The number of bits allocated per pixel. The formula for available colours is:
          Number of colours=2n\text{Number of colours} = 2^n
          where nn represents the colour depth in bits (e.g., 1-bit=2 colours1\text{-bit} = 2\text{ colours}, 8-bit=256 colours8\text{-bit} = 256\text{ colours}, 24-bit=16,777,216 colours24\text{-bit} = 16,777,216\text{ colours}).

    • Resolution: Can be defined by pixel dimensions (width×height\text{width} \times \text{height}) or pixel density (pixels per inch / ppi\text{ppi}).

  • Metadata

    • Defined as "data about data". Provides essential context required to render the raw bits accurately.

    • Examples: image dimensions, colour depth, creation date/time, GPS coordinates, camera settings, and file format.

  • Bitmap File Size Formula
      File Size (bits)=width (pixels)×height (pixels)×colour depth (bits)\text{File Size (bits)} = \text{width (pixels)} \times \text{height (pixels)} \times \text{colour depth (bits)}

    • To calculate size in bytes, divide the result by 88.


Lessons 12 & 13: Sound Representation & Calculations
  • Sound Digitisation

    • Natural sound is a continuous analogue pressure wave where amplitude dictates volume and frequency dictates pitch.

    • Computers convert analogue sound to digital through sampling (measuring wave amplitude at regular intervals and recording it as binary values).

    • Sample Rate: Number of audio samples recorded each second, measured in Hertz (Hz\text{Hz}). Standard professional audio uses 44.1 kHz44.1\,\text{kHz} (44,100 Hz44,100\,\text{Hz}).

    • Sample Resolution: Number of bits allocated to represent the amplitude of each sample. Standard high-fidelity audio utilizes 16-bit16\text{-bit} resolution (65,53665,536 amplitude levels).

    • Raising sample rate or resolution enhances playback fidelity while directly increasing file size.

  • Sound File Size Formula
      File Size (bits)=Sample Rate (Hz)×Sample Resolution (bits)×Duration (seconds)\text{File Size (bits)} = \text{Sample Rate (Hz)} \times \text{Sample Resolution (bits)} \times \text{Duration (seconds)}


Lesson 14: Data Storage Units and Prefixes
  • Hierarchy of Storage Units

    • Bit (b\text{b}): Single binary digit (00 or 11)

    • Nibble: 4 bits4\,\text{bits}

    • Byte (B\text{B}): 8 bits8\,\text{bits}

    • Kilobyte (kB\text{kB}): 1,000 bytes1,000\,\text{bytes}

    • Megabyte (MB\text{MB}): 1,000 kB1,000\,\text{kB}

    • Gigabyte (GB\text{GB}): 1,000 MB1,000\,\text{MB}

    • Terabyte (TB\text{TB}): 1,000 GB1,000\,\text{GB}

    • Petabyte (PB\text{PB}): 1,000 TB1,000\,\text{TB}

  • Decimal vs. Binary Prefixes

    • Commercial manufacturers use base-10 decimal prefixes (1 kB=1,000 B=103 B1\,\text{kB} = 1,000\,\text{B} = 10^3\,\text{B}).

    • Computing architectures rely on base-2 binary prefixes:

    • Kibibyte (KiB\text{KiB}): 1,024 bytes=210 bytes1,024\,\text{bytes} = 2^{10}\,\text{bytes}

    • Mebibyte (MiB\text{MiB}): 1,048,576 bytes=220 bytes1,048,576\,\text{bytes} = 2^{20}\,\text{bytes}

    • Gibibyte (GiB\text{GiB}): 230 bytes2^{30}\,\text{bytes}

    • Tebibyte (TiB\text{TiB}): 240 bytes2^{40}\,\text{bytes}


Lessons 15 & 16: Data Compression & Run-Length Encoding
  • **Lossy vs