Chapter 05 of 22 Part I: Digital Foundations

Recovering the Impossible

Each project below is tailored to a specific algorithm and scientific question from Chapter 05, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.

Project 1 of 3 · v1-c05-p01 Intermediate · ~30 min

Hamming(7,4) Syndrome Error Corrector

Lab activity: Lab 1 — Repair a bit · Related code: block-01.js, block-04.js · Pioneer: View profile

Real-World Problem: ECC server RAM and satellite links must repair single-bit errors automatically in real time.
Scientific Question: How do three overlapping parity checks spell out the exact binary address of a corrupted bit?

Objective: Implement Hamming(7,4) encoding, inject every possible single-bit error (positions 1–7), and verify automatic repair.

Hypothesis to Test: The 3-bit syndrome (s4 s2 s1) will always equal the 1-based index of the single flipped bit.

Step-by-Step Implementation

  1. Place 4 data bits at positions 3, 5, 6, 7 and compute parity bits P1, P2, P4 at positions 1, 2, 4.
  2. Loop over positions 1 through 7, flipping one bit at a time.
  3. Compute syndrome bits s1, s2, s4 via XOR and combine as s1 + 2*s2 + 4*s4.
  4. Flip bit (syndrome - 1) and verify the decoded 4 data bits match the original.
Concrete Input: 4-bit data nibble [1, 0, 1, 1] -> 7-bit codeword; flip position 5.
Expected Output: Encoded [0, 1, 1, 0, 0, 1, 1]; after flipping pos 5 -> syndrome = 5 (101₂) -> bit 5 flipped back -> exact recovery.

Test Cases: All 7 single-bit flips recover 100%; 0 flips -> syndrome 0; 2 flips -> miscorrected (demonstrates Hamming(7,4) limit).

Boundary Condition: Adding an 8th overall parity bit creates SECDED Hamming(8,4) which detects (without miscorrecting) 2-bit errors.

Common Mistake to Avoid: Mixing 0-based JavaScript array indices with 1-based Hamming bit positions.

Interpreting Results: Smart placement of parity bits at powers of two achieves single-error correction with logarithmic overhead.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 05 before testing the boundary case: Adding an 8th overall parity bit creates SECDED Hamming(8,4) which detects (without miscorrecting) 2-bit errors.

Extension Challenge: Upgrade the function to Hamming(8,4) SECDED so double-bit errors are flagged as uncorrectable instead of miscorrected.

Reflection Question: Why did Richard Hamming invent this code after watching weekend mainframe jobs halt on single parity errors?

Project 2 of 3 · v1-c05-p02 Intermediate · ~25 min

RAID-5 XOR Drive Failure Simulator

Lab activity: Lab 2 — Rebuild a drive · Related code: block-02.js, block-05.js · Pioneer: View profile

Real-World Problem: Hard drives eventually fail mechanically, yet cloud services cannot afford to lose data on a single disk failure.
Scientific Question: How can bitwise XOR across N data drives rebuild any single failed drive with only one parity drive of overhead?

Objective: Stripe bytes across fictional drives, compute XOR parity, erase one drive completely, and reconstruct it bit-for-bit.

Hypothesis to Test: Because XOR is associative and self-inverse (A XOR A = 0), XORing all surviving drives with parity reproduces the missing drive identically.

Step-by-Step Implementation

  1. Represent two or three fictional drives as equal-length byte arrays.
  2. Compute the parity drive by XORing corresponding bytes across all data drives.
  3. Simulate failure of any single drive (data OR parity) by zeroing it out.
  4. Reconstruct the missing drive from the remaining drives and verify byte equality.
Concrete Input: Drive 1: [0x41, 0x42], Drive 2: [0x53, 0x54] -> Parity: [0x12, 0x16].
Expected Output: Erase Drive 2 -> Drive 1 XOR Parity = [0x53, 0x54] (100% byte-identical rebuild).

Test Cases: Lose Drive 1 -> rebuilt; Lose Drive 2 -> rebuilt; Lose 2 drives simultaneously -> unrecoverable.

Boundary Condition: If two drives fail before rebuild completes, single-parity RAID-5 loses data (requiring RAID-6).

Common Mistake to Avoid: Believing RAID protects against accidental file deletion or ransomware.

Interpreting Results: RAID provides hardware fault tolerance, while offline/versioned backups protect against human or software errors.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 05 before testing the boundary case: If two drives fail before rebuild completes, single-parity RAID-5 loses data (requiring RAID-6).

Extension Challenge: Simulate a 4-drive array where parity rotates across drives per stripe (true RAID-5 layout).

Reflection Question: Why is the rebuild window after one drive fails the most dangerous time for a RAID-5 array?

Project 3 of 3 · v1-c05-p03 Applied · ~30 min

Deep-Space Packet Recovery Pipeline

Lab activity: Lab 3 — Send a message to Earth · Related code: block-03.js, block-04.js, block-05.js · Pioneer: View profile

Real-World Problem: Spacecraft telemetry suffers random bit errors during long-distance transmission back to Earth.
Scientific Question: How many bit errors can a multi-nibble Hamming-encoded message survive when errors are spread across blocks?

Objective: Split an ASCII message into 4-bit nibbles, Hamming-encode each nibble, inject noise, and measure recovery.

Hypothesis to Test: Encoding each 4-bit nibble into 7 bits repairs up to 1 error per 7-bit block, increasing message size by 75%.

Step-by-Step Implementation

  1. Convert each ASCII character into high and low 4-bit nibbles.
  2. Encode each nibble with Hamming(7,4) and concatenate into a transmission stream.
  3. Inject 1 bit error per block vs. 2 bit errors in the same block.
  4. Decode and compare original vs. recovered text and bandwidth overhead.
Concrete Input: Message "OK" (2 bytes = 4 nibbles -> 28 transmitted bits) with 1 error in each block.
Expected Output: 4 total bit errors (1 per block) -> decoded back to exact "OK".

Test Cases: 1 error/block -> exact text; 2 errors in 1 block -> corrupted character.

Boundary Condition: Burst errors hitting consecutive bits in one block defeat simple Hamming without interleaving.

Common Mistake to Avoid: Forgetting to recombine high nibble (<< 4) and low nibble (& 0x0F) into a byte.

Interpreting Results: Interleaving bits across blocks spreads burst noise so single-error codes can repair bursts.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 05 before testing the boundary case: Burst errors hitting consecutive bits in one block defeat simple Hamming without interleaving.

Extension Challenge: Add bit-interleaving across 4 blocks so a 4-bit consecutive burst becomes 1 error per block and recovers cleanly.

Reflection Question: How do engineers balance bandwidth overhead against reliability on low-power spacecraft links?