Representing Data (OUTLINE)#

Status: outline only. No prose written, no exercises written. This file exists to pin down scope, vocabulary, and standards claims before any drafting happens. Delete this block when the chapter is real.

Placement: after Chapter 7 (Iteration and Search), before Chapter 8. Slot: one week. Not a Monday insert; this is bigger than 6b. Prerequisites used: iteration and string traversal (ch7), return values (ch6), recursion (ch5), docstrings and doctests (6b), // and % (ch1).

Why it exists: AP topics 2.1 and 2.2 and CA DA.8 and DA.9 currently have no carrier anywhere in the course. Big Idea 2 is 17 to 22% of the multiple choice, and 20 of its 22 vocabulary terms are unmet. This chapter closes the representation half. The analysis half (2.3, 2.4) stays with chapters 12 and 13.

Why after 7 and not earlier: run-length encoding needs iteration over a string. Placing this earlier splits the block in two and orphans the compression code.

What this chapter covers#

1. Everything is bits#

  • One physical thing, two states. Why two and not ten

  • The same bits mean different things depending on what you claim they are

  • Terms: bit, byte, binary, digital data

2. Place value, base 2#

  • Base 10 as a system of powers, not as “the way numbers are”

  • Base 2 as the identical system with a different base

  • Reading a byte: 8 bits, 0 to 255, and where 255 comes from

  • Terms: binary, decimal, place value

  • Watch: this is the section where math-anxious students disengage. Anchor it in odometers and place value they already own, not in arithmetic drills

3. Conversion, by hand and in code#

  • Decimal to binary: repeated division by 2, collecting remainders

  • Binary to decimal: sum of powers

  • Built-ins: bin(), int(s, 2), format()

  • Code: to_binary(n) and from_binary(s), written by students

  • Code: the round trip as a doctest. from_binary(to_binary(37)) returns 37. First time students write a test whose expected value they did not compute by hand

  • Optional: recursive to_binary, since repeated division is a natural recursion

4. Hexadecimal as shorthand#

  • Four bits per digit, so one byte is exactly two hex digits

  • Where they’ll actually meet it: color codes, I2C addresses in the Pico unit, ROS2 later

  • Terms: hexadecimal

  • Scope note: teach as notation, not as an exam topic. The Pico I2C chapter is the place where it earns its keep

5. Bits as text#

  • ASCII: a table, nothing more

  • ord() and chr()

  • Unicode and why 128 characters stopped being enough

  • Terms: ASCII, Unicode, character encoding

  • Hook: the mojibake demo. Text that “looks broken” is bits read with the wrong claim

6. Bits as color#

  • RGB, three bytes, 0 to 255 each

  • Hex color codes as the same three bytes in the notation from section 4

  • Terms: RGB, pixel

7. Analog and digital#

  • Continuous versus discrete. Sound and light are analog; storage is not

  • Sampling: rate and bit depth as two separate knobs

  • Watch: students think only about rate. Bit depth needs its own example

  • Why no sample is ever the whole signal

  • Terms: analog data, digital data, sampling

  • Teach as a contrast pair. Individually these definitions are near-empty

8. When the bits run out#

  • Overflow: a value too large for the bits available

  • Python hides this. Integers are arbitrary precision, so overflow needs a deliberate demo. Fixed-width arithmetic, a hand-rolled 8-bit adder, or the Pico

  • Roundoff: revisit 0.1 + 0.2 from Chapter 1 and the forward reference from 6b

  • Terms: overflow error, roundoff error

  • Scope note: DAT-1.B.3 puts specific range limits for real numbers out of scope. Explain the cause, do not drill the ranges

9. Compression#

  • The idea: fewer bits, same or nearly the same meaning

  • Lossless: run-length encoding, built and tested by students

  • Code: rle_encode(s) and rle_decode(s), round-trip tested

  • The case that matters: input where RLE makes the output larger. This is the insight the exam actually tests

  • Lossy: what JPEG and MP3 throw away, and why you cannot get it back

  • Choosing between them: the exam tests the choice, not the definitions

  • Terms: lossless compression, lossy compression, compression ratio

10. Debugging#

  • Errors of interpretation: right bits, wrong claim about what they mean

  • Off-by-one in place value. The 2**n versus 2**(n-1) mistake

  • Round-trip tests as the tool that catches encoding bugs the eye cannot

Deliberately not here#

Topic

Where instead

Why

Metadata

Little Brother

EXIF is simultaneously DAT-2.B and the surveillance thread. Free coverage on both sides

Data cleaning, correlation, data sets, information

Chapters 12, 13

Topic 2.3, already carried

Data visualization

still unassigned

CA DA.10, no plotting anywhere in the course. Not this chapter’s job, but do not lose track of it

Bitwise operators

nowhere yet

Not an AP topic. May earn a place in the robotics unit

Two’s complement

nowhere

Beyond scope, and Python hides it completely

Floating-point layout

nowhere

DAT-1.B.3 explicitly excludes real-number range limits

Glossary#

Terms this chapter claims. AP tier in brackets: F foundational, C needs instruction time, L low priority. Terms marked ★ are high-frequency on released exam items.

bit [F]: A single binary digit, 0 or 1.

byte [F]: Eight bits. Enough to hold one of 256 values.

binary [L, ★]: Base-2 representation, using only the digits 0 and 1.

decimal [F]: Base-10, the system you already use.

hexadecimal [F]: Base-16, using 0 through 9 and A through F. Four bits per digit, so one byte is exactly two hex digits.

digital data [C]: Values represented in discrete steps, ultimately as bits.

analog data [C]: Values that vary continuously and smoothly, with no steps.

sampling [C]: Approximating an analog signal by measuring it at regular intervals. Two independent settings: how often you measure (rate) and how precisely you record each measurement (bit depth).

ASCII [F]: A table assigning a number from 0 to 127 to each of a small set of characters.

Unicode [F]: A far larger table, covering the writing systems ASCII left out.

character encoding [C]: The agreement about which numbers stand for which characters. Read bits with the wrong encoding and you get the right data as the wrong text.

RGB [F]: Color stored as three numbers, the amounts of red, green, and blue, each usually one byte.

overflow error [C]: An error that happens when a value is too large for the number of bits available to hold it.

roundoff error [C]: A loss of precision that happens because a fixed number of bits cannot represent some numbers exactly.

lossless compression [C, ★]: Reduces size while allowing the original to be reconstructed exactly.

lossy compression [C, ★]: Reduces size further, but only an approximation of the original can be recovered.

compression ratio [–]: Compressed size divided by original size. (Ours, not exam vocabulary. Included because it makes the lossless/lossy tradeoff measurable rather than verbal.)

run-length encoding [–]: A lossless scheme that replaces runs of a repeated value with the value and a count. (Ours. The exam names no specific algorithm.)

See also: the full vocabulary glossary collects every term in this book, alphabetized, alongside the complete AP CSP exam vocabulary list.

Vocabulary load#

Fifteen to seventeen new terms in one week, which is the largest single-chapter vocabulary load in the course.

Three mitigations, all built into the section order above:

  1. Contrast pairs. analog/digital, lossless/lossy, bit/byte, overflow/roundoff. Eight terms taught as four ideas.

  2. Notation terms carry themselves. binary, decimal, hexadecimal, ASCII, RGB are all “here is a table, here is how to read it.” They need exposure, not instruction time.

  3. Defer the quiz. Put these on the following Monday’s entry quiz, not the same week’s.

The terms that genuinely need instruction time, and where the period actually goes: sampling (two knobs, not one), lossless versus lossy (the choice, not the definitions), and overflow (which Python actively hides).


Standards alignment#

AP CSP: 2.1 Binary Numbers, 2.2 Data Compression. Big Idea 2, 17-22% of the exam California 9-12: 9-12.DA.8, 9-12.DA.9 CSTA 2026: (TBD) CA CTE (ICT): (TBD)

Exclusion to respect: DAT-1.B.3 puts specific range limitations for real numbers outside course and exam scope. Explain why roundoff happens; do not drill float ranges.

Open questions before drafting#

  1. Overflow demo. Python won’t overflow natively. Options: simulate fixed width with masking, build an 8-bit adder by hand, or borrow the Pico. The masking version is the least motivated and the Pico version is the most, but the Pico version means this chapter depends on hardware being available in the fall.

  2. Does this chapter get exercises in the notebook, or a separate problem set? It is part concept and part code, and the concept half does not fit the notebook exercise format well. Possibly notebook exercises for sections 3 and 9, written response elsewhere.

  3. Sound or image for the sampling demo? Sound is more intuitive and needs audio in the classroom. Image is easier to show in a notebook and connects to section 6.

  4. Time. One week is the assumption. Ten sections is a lot for one week, and sections 1 and 2 may collapse into one. Worth cutting to fit before drafting rather than after.

  5. Chapter number. 7b follows the 6b convention, but check_sync.py and the build scripts assume numeric chapter names. Confirm 6b’s fix covers this before adding a second non-numeric chapter.