Chapter 03 of 22 Part I: Digital Foundations

The Secret Language of Barcodes

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

Project 1 of 3 · v1-c03-p01 Foundational · ~30 min

EAN-13 95-Module Barcode Encoder

Lab activity: A · Build a barcode · Related code: block-01.js, block-04.js · Pioneer: View profile

Real-World Problem: Retail scanners must read 13-digit product IDs reliably from printed packaging at any checkout speed.
Scientific Question: How do 7-module L, G, and R encodings pack 13 decimal digits into 95 black-and-white modules?

Objective: Encode any 12-digit prefix into its 13th check digit and full 95-bit EAN-13 bar pattern.

Hypothesis to Test: Every EAN-13 digit occupies 7 modules containing exactly two black bars and two white spaces.

Step-by-Step Implementation

  1. Compute the 13th check digit using alternating weights 1 and 3 modulo 10.
  2. Look up the 6-character L/G parity pattern determined by the leading digit (4 -> LGLGGL).
  3. Emit Left Guard (101), 6 left digits (42 modules), Center Guard (01010), 6 right R-digits (42 modules), Right Guard (101).
  4. Verify total module count equals 3 + 42 + 5 + 42 + 3 = 95.
Concrete Input: 12-digit prefix: 400638133393
Expected Output: Check digit = 1; full code = 4006381333931; 95-bit pattern starting 101 and ending 101.

Test Cases: 400638133393 -> check 1; 978030640615 -> check 7; total length always 95 bits.

Boundary Condition: Leading digit 0 uses LLLLLL (backward-compatible with 12-digit UPC-A).

Common Mistake to Avoid: Using 1-based vs. 0-based index backwards when applying weights 1 and 3.

Interpreting Results: Encoding the first digit in the parity of the next six digits added global country prefixes without widening existing barcodes.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 03 before testing the boundary case: Leading digit 0 uses LLLLLL (backward-compatible with 12-digit UPC-A).

Extension Challenge: Verify that every L-code has an odd number of 1s while every G-code and R-code has an even number of 1s.

Reflection Question: How did George Laurer's rectangular UPC/EAN geometry balance printing tolerances with laser optics?

Project 2 of 3 · v1-c03-p02 Intermediate · ~30 min

Bidirectional Optical Barcode Scanner

Lab activity: B · Become the scanner · Related code: block-02.js, block-05.js · Pioneer: View profile

Real-World Problem: Cashiers swipe items left-to-right, right-to-left, and upside-down without aligning them.
Scientific Question: How does a scanner know immediately whether it scanned a barcode forward or backward?

Objective: Decode a 95-module bitstring in either orientation by inspecting guard bars and L/G/R parity signatures.

Hypothesis to Test: Because R-codes always start with a 1 (dark bar) and L/G-codes always start with a 0 (space), reversing a scan produces invalid L/G patterns on the left.

Step-by-Step Implementation

  1. Verify start (101), center (01010), and end (101) guard bars at fixed module offsets.
  2. Attempt decoding the left six 7-bit chunks against L/G tables and right six against R table.
  3. If forward decoding fails, reverse the entire 95-bit array and decode again.
  4. Recover the leading digit from the 6-bit L/G sequence and verify the 13th check digit.
Concrete Input: Reversed 95-bit string of 4006381333931.
Expected Output: Orientation detected as REVERSED -> bitstring flipped -> decoded 4006381333931 (check VALID).

Test Cases: Forward 95 bits -> valid; Reversed 95 bits -> valid; 1 corrupted module -> rejected.

Boundary Condition: Missing quiet zones around the barcode cause real optical scanners to miss the start guard.

Common Mistake to Avoid: Reversing each digit individually instead of reversing the full 95-module scan.

Interpreting Results: Asymmetric parity sets make orientation self-describing without wasting extra bars.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 03 before testing the boundary case: Missing quiet zones around the barcode cause real optical scanners to miss the start guard.

Extension Challenge: Simulate a 1-module smudge and show how the scanner detects an invalid 7-module codeword.

Reflection Question: Why do barcodes fail cleanly (refuse to scan) instead of ringing up a wrong product?

Project 3 of 3 · v1-c03-p03 Foundational · ~20 min

Fictional Supermarket Inventory Lookup

Lab activity: C · Run a pretend supermarket · Related code: block-03.js, block-04.js, block-05.js, block-06.js · Pioneer: View profile

Real-World Problem: Store prices change weekly for sales and inflation without reprinting millions of product boxes.
Scientific Question: Why is separating product identity (barcode) from attributes (price/name) a core database principle?

Objective: Connect decoded EAN-13 identifiers to a fictional store catalog, handle unknown codes, and compute a receipt.

Hypothesis to Test: Updating a product's price in one catalog table immediately changes the checkout total without changing its barcode.

Step-by-Step Implementation

  1. Validate each scanned 13-digit code with the EAN-13 check-digit function first.
  2. Look up valid codes in a fictional JavaScript Map of items with integer-cent prices.
  3. Handle both invalid check digits (scan error) and valid-but-unlisted items separately.
  4. Update one item's price in the catalog and re-scan the identical barcode.
Concrete Input: Scan 3 fictional EAN-13 codes (2 valid in catalog, 1 valid EAN-13 not in catalog).
Expected Output: Itemized receipt with integer-cent subtotal + graceful "Item not found in store catalog" alert.

Test Cases: Invalid check digit -> "Rescan item"; Valid unlisted EAN -> "Price check needed".

Boundary Condition: Empty cart outputs $0.00; integer cents prevent floating-point rounding drift.

Common Mistake to Avoid: Treating a valid check digit as proof that the product exists in inventory.

Interpreting Results: Barcodes are foreign keys into a database, not self-contained price tags.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 03 before testing the boundary case: Empty cart outputs $0.00; integer cents prevent floating-point rounding drift.

Extension Challenge: Add a quantity counter and 5% fictional discount rule while keeping all math in integer cents.

Reflection Question: How does separating identifiers from data make global supply chains scalable?