AP COMPUTER SCIENCE PRINCIPLES · 2026–27 · UNIT 2

Digital Information & Encoding

Understand how bits become text, pictures and sampled signals. Predict representation size, test encoding choices, and explain when compression is worth the tradeoff.

Start here: a visual guide to this unit

This unit uses the same routine established in Unit 1. Your website is the organizer; CodeHS, AP Classroom, and the student workbook are its connected resources.

1 · WebsiteOpen the numbered lesson and see the model.
2 · Video resourcesFollow the assigned CodeHS and AP Daily work.
3 · WorkbookSTRIDES notes, vocabulary, diagrams and predictions.
4 · Coding & labsTest the model; explain evidence and revise.
Model habit: Before testing a 4-bit binary number, predict the largest value the representation can store. Then set the model to that value, add one, and explain the result using the bit width—not a guess.

How Unit 2 fits the course

Eight-unit course roadmap

1 · FoundationsComputational thinking
2 · Digital InformationBits, text, images, sampling and compression
3 · Logic & ControlAlgorithms and selection/iteration
4 · AbstractionLists and procedures
5 · AlgorithmsEfficiency and simulation
6 · SystemsNetworks and security
7 · Data & SocietyExtracting information and impacts
8 · Create & ReviewPerformance task and AP preparation

Scope note: College Board Big Idea 2 (Data) includes Topics 2.1–2.4. This unit concentrates on 2.1 Binary Numbers and 2.2 Data Compression. Topics 2.3–2.4 (extracting information and using programs with data) return in Unit 7. CodeHS 8.10 Cryptography is deferred to our Unit 6.

Lesson map and assignments

The CodeHS numbers below come from AP Computer Science Principles in Python (2025), Module 8. AP Classroom videos and Topic Questions must be assigned in your teacher account.

WebsiteTopicCodeHS activity numbersAP ClassroomWorkbook pagesDone
2.1Binary Numbers & Place Value8.1.1, 8.1.5; 8.2.1, 8.2.4, 8.2.62.1 Binary Numbers8–10□
2.2Capacity, Overflow & Hexadecimal8.2.7, 8.2.8; 8.5.1, 8.5.3, 8.5.42.1 Binary Numbers11–13□
2.3Encoding Text & Unicode8.3.1, 8.3.4, 8.3.6, 8.3.8, 8.3.92.1 Binary Numbers (representation)14–16□
2.4Pixels, RGB & Image Resolution8.4.1, 8.4.5, 8.4.7; 8.6.1, 8.6.6, 8.6.92.1 Binary Numbers (images and representation)17–19□
2.5Sampling Analog Information8.9.5 Analog to Digital; 8.9.6 Respond: Analog to Digital2.1 Binary Numbers (analog and digital)20–22□
2.6Lossless & Lossy Compression8.8.1, 8.8.3, 8.8.5, 8.8.7; 8.9.1, 8.9.42.2 Data Compression23–25□
2.7Digital Encoding Studio: Design Challenge8.3.8; 8.4.7; 8.6.9; 8.8.7; optional 8.11.1 after assigned lessons2.1 and 2.2 synthesis26–28□

Guided notes, illustrations and worked examples

Read the worked example first, then complete the different questions in your student workbook. Expand “Illustrate and plan” for the investigation setup.

LESSON 2.1 · WORKBOOK pp. 8–10

Binary Numbers & Place Value

Represent unsigned whole numbers using bits and explain why computers use binary.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.1.1, 8.1.5; 8.2.1, 8.2.4, 8.2.6

3 · AP Classroom

AP Daily & Topic Questions
2.1 Binary Numbers — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 8–10.

Core notes

  • A binary position represents a power of two (1, 2, 4, 8, ...).
  • A fixed number of bits limits the number of distinct patterns: 2^n.

Vocabulary

bit
A single binary digit, 0 or 1.
byte
A group of 8 bits.
binary
A base-2 number system using 0 and 1.
place value
The weight assigned to a digit by its position.

Worked example

Convert 00101101 from unsigned binary to decimal. Show the weights you add.

Reasoning: 32 + 8 + 4 + 1 = 45.

Practice before testing

  1. Explain what changes between decimal place values and binary place values.
  2. Why does a computer need an agreed-upon encoding to interpret a bit pattern?
Illustrate and plan

Diagram: Draw an 8-bit place-value strip. Label 128, 64, 32, 16, 8, 4, 2, 1 and shade the 1-bits for 45.

Algorithm planning: READ an unsigned decimal integer 0..255; for each descending weight, write 1 if the remaining value is at least the weight, subtract it, otherwise write 0.

Investigate: Use the website Binary Explorer and CodeHS Binary Game. Try 13, 45 and 127; record a prediction before checking.

LESSON 2.2 · WORKBOOK pp. 11–13

Capacity, Overflow & Hexadecimal

Predict fixed-width overflow and translate among binary, decimal, and hexadecimal.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.2.7, 8.2.8; 8.5.1, 8.5.3, 8.5.4

3 · AP Classroom

AP Daily & Topic Questions
2.1 Binary Numbers — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 11–13.

Core notes

  • An unsigned n-bit register stores values 0 through 2^n - 1.
  • One hex digit corresponds exactly to 4 bits.

Vocabulary

overflow
A result that exceeds the representable range.
hexadecimal
Base-16 notation using 0–9 and A–F.
nibble
Four bits, representing one hex digit.
capacity
The number of distinct values a representation can store.

Worked example

Convert hex 3A to 8-bit binary and decimal, then explain what 1111 + 1 means in a fixed 4-bit unsigned register.

Reasoning: 3A -> 0011 1010 -> 58; 1111 + 1 -> 0000 with a carry lost in a fixed 4-bit register.

Practice before testing

  1. What is the maximum value in an unsigned 6-bit system? Explain.
  2. Why is hexadecimal a convenient shorthand for a long binary pattern?
Illustrate and plan

Diagram: Draw two groups of four bits for 3A. Use a carry arrow to illustrate 4-bit overflow.

Algorithm planning: READ a nonnegative number; IF value > 15, REPORT out of range for 4-bit unsigned storage; ELSE encode using weights 8,4,2,1.

Investigate: Set Bit Explorer to 4 bits and test 14, 15, 16; then use CodeHS Overflow Error and Binary to Hex Game.

LESSON 2.3 · WORKBOOK pp. 14–16

Encoding Text & Unicode

Encode characters as bits and distinguish ASCII, Unicode code points, and UTF-8 bytes.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.3.1, 8.3.4, 8.3.6, 8.3.8, 8.3.9

3 · AP Classroom

AP Daily & Topic Questions
2.1 Binary Numbers (representation) — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 14–16.

Core notes

  • ASCII value 65 corresponds to the capital letter A.
  • UTF-8 uses 1 to 4 bytes for Unicode scalar values; not every character occupies one byte.

Vocabulary

character
An individual text symbol or control character.
ASCII
A 7-bit character code with 128 defined values.
Unicode
A standard assigning code points to characters.
UTF-8
A variable-length encoding of Unicode code points into bytes.

Worked example

Encode CAB using 8-bit ASCII-compatible bytes. Use the values C=67, A=65, B=66.

Reasoning: C 01000011; A 01000001; B 01000010, for 24 bits total.

Practice before testing

  1. Why can the bits 01000001 represent A in one context and 65 in another?
  2. Why is it inaccurate to say every Unicode character takes eight bits?
Illustrate and plan

Diagram: Draw a three-column message packet with character, decimal code and 8-bit representation for CAB.

Algorithm planning: FOR each character in a message: LOOK UP its code point; ENCODE it as UTF-8 bytes; APPEND bytes to output.

Investigate: Compare the byte lengths of "DATA", "café", and "🚀" in the Text Encoder. Record one surprise and explain it.

LESSON 2.4 · WORKBOOK pp. 17–19

Pixels, RGB & Image Resolution

Explain raster images and estimate raw storage for images with different dimensions and color depths.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.4.1, 8.4.5, 8.4.7; 8.6.1, 8.6.6, 8.6.9

3 · AP Classroom

AP Daily & Topic Questions
2.1 Binary Numbers (images and representation) — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 17–19.

Core notes

  • Raw pixel bits = width × height × bits per pixel, excluding file headers or compression.
  • 24-bit RGB commonly allocates eight bits per color channel.

Vocabulary

pixel
The smallest addressable element of a raster image.
resolution
Pixel dimensions of a digital image.
color depth
Bits used to describe a pixel color.
RGB
Color model combining red, green and blue channels.

Worked example

Estimate the raw bits and bytes for an 8×8 image at 24 bits/pixel (ignore headers).

Reasoning: 8 × 8 × 24 = 1536 bits = 192 bytes.

Practice before testing

  1. What information is lost when a 16×16 image is reduced to 4×4 pixels?
  2. Why can an RGB color be represented by three 0..255 values?
Illustrate and plan

Diagram: Color a 4×4 pixel grid with three colors; label sample RGB triples and one 24-bit raw pixel.

Algorithm planning: FOR every row: FOR every column: READ the pixel RGB values and STORE three 8-bit channels.

Investigate: Create a pattern in the Pixel Lab, change the RGB sliders and record a raw file-size prediction.

LESSON 2.5 · WORKBOOK pp. 20–22

Sampling Analog Information

Model sampling and quantization, and explain how choices affect precision and storage.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.9.5 Analog to Digital; 8.9.6 Respond: Analog to Digital

3 · AP Classroom

AP Daily & Topic Questions
2.1 Binary Numbers (analog and digital) — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 20–22.

Core notes

  • More samples can capture finer time variation, but sampling does not guarantee perfect reconstruction.
  • Quantization rounds amplitudes to available levels; increasing bit depth provides more possible levels.

Vocabulary

analog
Information that changes continuously.
sample
Measurement taken at a particular point in time.
sampling rate
Number of samples taken per second.
quantization
Mapping measured values onto discrete allowed levels.

Worked example

Estimate raw mono audio size at 8000 samples/s, 8 bits/sample, for 3 seconds.

Reasoning: 8000 × 8 × 3 = 192000 bits = 24000 bytes (no headers or compression).

Practice before testing

  1. How is sampling rate different from the number of bits per sample?
  2. Why might a small sampling rate miss rapid changes?
Illustrate and plan

Diagram: Sketch one continuous wave and two sets of sample points, one sparse and one dense.

Algorithm planning: EVERY 1/rate seconds: MEASURE analog amplitude; ROUND to nearest allowed level; STORE resulting code.

Investigate: Use Sampling Lab at 4, 12 and 32 samples/cycle, and 2, 3, 5 quantization bits; predict which reconstruction is closer.

LESSON 2.6 · WORKBOOK pp. 23–25

Lossless & Lossy Compression

Compare lossless and lossy approaches using file-size calculations and reconstruction tests.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.8.1, 8.8.3, 8.8.5, 8.8.7; 8.9.1, 8.9.4

3 · AP Classroom

AP Daily & Topic Questions
2.2 Data Compression — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 23–25.

Core notes

  • A compression method can sometimes make a particular input larger due to overhead.
  • Lossy methods trade some accuracy or fidelity for smaller representations.

Vocabulary

compression
Reducing the number of bits needed to represent data.
lossless
Compression that permits exact reconstruction.
lossy
Compression that discards some information.
run-length encoding
Representing repeated values by a count and symbol.

Worked example

Encode AAAAAABBBCC with count-symbol RLE and compare the number of characters.

Reasoning: 6A3B2C; 6 encoded characters versus 11 original characters under a simple one-character count convention.

Practice before testing

  1. Which method is appropriate for a text document that must be recovered exactly? Why?
  2. Why is it impossible to know which method is smaller without considering the data?
Illustrate and plan

Diagram: Draw a before/after run diagram for AAABBBBBCCCC. Label run count, original length and encoded length.

Algorithm planning: SCAN from left to right; COUNT consecutive matching symbols; EMIT each run as count and symbol.

Investigate: Try two messages in RLE Studio, then compare lossless restoration to a deliberately reduced-resolution pixel image.

LESSON 2.7 · WORKBOOK pp. 26–28

Digital Encoding Studio: Design Challenge

Choose and justify a representation given a data type, storage budget, and quality requirement.

1 · This website

Read the worked example; make a prediction; use the named lab below.

2 · CodeHS (2025 Python)

Digital Information, Module 8
Activities 8.3.8; 8.4.7; 8.6.9; 8.8.7; optional 8.11.1 after assigned lessons

3 · AP Classroom

AP Daily & Topic Questions
2.1 and 2.2 synthesis — teacher-assigned

4 · Workbook

STRIDES, visual model, prediction, pseudocode and lab reflection on pp. 26–28.

Core notes

  • A useful digital design includes a data representation and information describing how to decode it.
  • Selecting an algorithm requires comparing evidence with the stated priorities.

Vocabulary

constraint
A required limit on a solution.
tradeoff
A gain in one quality that may cost another.
metadata
Information describing how to interpret other data.
fidelity
How closely reconstructed data resembles the original.

Worked example

A 4×4 black/white icon must be transmitted. Compare raw 1-bit pixels with a defined RLE format; explain what you would send.

Reasoning: Raw 4×4 = 16 bits = 2 bytes, excluding headers. RLE may or may not improve size; define count encoding and include metadata.

Practice before testing

  1. Why must a receiver know the dimensions and encoding of an image?
  2. Which evidence is needed to defend a compression decision?
Illustrate and plan

Diagram: Draw an encoder → packet + metadata → decoder diagram. Label exactly where bits are interpreted.

Algorithm planning: CHOOSE encoding; CALCULATE expected size; ENCODE data; TRANSMIT metadata and payload; DECODE; VERIFY fidelity.

Investigate: Complete the Unit 2 Digital Encoding Studio and compare your final choices against a hard size budget.

Interactive Digital Information Lab

Each experiment has a prediction question, a working model and an observation to record. Calculated sizes are raw payload estimates unless otherwise stated.

Lab A · Binary Explorer and overflow

Eight unsigned bits have place values from 128 to 1. Click bits or use the decimal slider to change the pattern.

Predict what happens to 1111 when you add one using only four bits.

Workbook: 2.1 pp. 8–10; 2.2 pp. 11–13. Underflow, signed integer conventions, and arbitrary-precision behavior are outside this simple unsigned model.

Lab B · Text to UTF-8 bytes

Different encodings interpret the same bytes differently. This explorer shows each UTF-8 byte and its binary representation. Try DATA, café, and 🚀.

UTF-8 bytes differ from character counts; the page reports Unicode code points as well as bytes. Workbook lesson 2.3 pp. 14–16.

Lab C · Pixel canvas and RGB storage

Click cells to paint an 8×8 raster. Change the RGB sliders and notice how the visible color changes while the raw 24-bit RGB payload size stays fixed.

30
100
160

One-bit black/white format: 64 bits = 8 raw bytes. Full 24-bit RGB: 1536 bits = 192 raw bytes. No file header or compression is counted. Workbook 2.4 pp. 17–19.

Lab D · Analog sampling and quantization

A continuous sine wave is sampled at equally spaced times, then each sampled amplitude is rounded to one of a finite number of levels.

The model uses one smooth sine period and simple uniform rounding. Error shown is mean absolute difference at sampled positions; it does not establish perfect signal reconstruction. Workbook 2.5 pp. 20–22.

Lab E · Run-length encoding (lossless)

For this model, each run is stored as one byte for count (1–255) and one byte for the ASCII symbol. This is a defined instructional format, not a standard compressed file format. Choose a message of ASCII letters or digits.

Try ABABAB and AAAAAAAAAAAAAAAA. Why does one expand? Workbook 2.6 pp. 23–25.

Lab F · Digital Encoding Studio: meet the payload budget

A field station can send at most 10 payload bytes. Its eight-character ASCII status already uses eight bytes. Compare a raw 8×8 black-and-white icon with run-length encoding of the current pixel grid. Headers and metadata are intentionally excluded from the payload-only comparison—identify their cost separately in your design.

Use your workbook project pages 29–32 for your diagram, metadata decisions, reconstruction evidence and claim/evidence/reasoning response. A uniform icon has just one run; a checkerboard has many short runs.

AP-style concept checks

These are original formative questions. They are not copied from AP Classroom. Make your choices before checking the explanations.

Q1. Which unsigned decimal number is represented by 00010110?
Q2. How many different bit patterns exist in six bits?
Q3. What happens to 15 + 1 in a fixed 4-bit unsigned wraparound model?
Q4. Why does a text decoder need a known encoding?
Q5. How many data bits are in an 8×8 monochrome image at one bit per pixel?
Q6. An 8×8 RGB image uses 24 bits per pixel. How many raw bytes?
Q7. Which change increases the number of amplitude levels available in quantization?
Q8. For a message that must be reconstructed exactly, choose
Q9. Why can run-length encoding increase file size?
Q10. Which is a defensible encoding design justification?

Select one answer for each question.

Planning, alignment and pacing

Suggested 9–11 block sequence

  1. Binary and place values (1 block)
  2. Capacity and hex (1 block)
  3. Text/Unicode (1 block)
  4. Pixels and RGB (1–2 blocks)
  5. Sampling and audio (1 block)
  6. Compression (1–2 blocks)
  7. Studio investigation and presentation (2 blocks)
  8. Review / assessment (1 block)

Assessment evidence

20-point workbook classwork: vocabulary/video notes 4; conceptual/STRIDES 4; diagrams/pseudocode 4; lab results 4; review/reflection 4.

Use CodeHS 8.11.1 only after deciding which Module 8 sections you assigned, since this website intentionally moves cryptography (8.10) into the later security unit.

AP Classroom: assign selected Topic 2.1 and 2.2 videos/questions now; postpone 2.3 and 2.4 until students encounter data analysis.

Important: The official 2026–27 AP CSP course description remains the reference for this unit. The announced AP CSP redesign takes effect for 2027–28, not this school year.

Student resources

Print and learn

Download Unit 2 Student Workbook

36 pages, matched to the seven website lessons. The teacher edition is distributed separately and never hosted here.

Course references

CodeHS AP CSP Python (2025) course outline

College Board AP CSP overview

AP Classroom sign-in

Unit 2 Student Workbook

Use the student workbook alongside the lessons, concept checks, and interactive labs.

Download the student workbook (PDF) Open workbook in a new tab

Open the student workbook PDF to view or download it.