Week 7 · Lesson 1 · 55 minutes

Check the data in the greenhouse kiosk

Use representation rules to check values and storage claims.

Planned lesson. Follow your teacher’s teaching order.

Source workbook pages: 42.

Resources

Vocabulary

Vocabulary
unsigned: A representation with no negative values; overflow: A result that does not fit the chosen width; metadata: Information needed to interpret stored data
55-minute lesson sequence
  1. 0–5 · Answer the retrieval alone. Compare one reason.
  2. 5–15 · Teacher models the example. Students predict each next step.
  3. 15–40 · Build, trace and test the main tasks. Work alone first; compare after a checkpoint.
  4. 40–50 · Check results. Explain a test and repair one error. Use the extension only if ready.
  5. 50–55 · Complete the exit alone. Save the evidence for the next lesson.

Try before notes

Convert 00101010 to decimal and hexadecimal.

Build the idea

Representation rules give bits a meaning. Identify width, unsigned or signed interpretation, units and file format before calculating. Python integers do not automatically obey a chosen fixed-width storage rule.

For an unsigned b-bit field the largest value is 2^b−1. If a stated system keeps only the lowest b bits, it discards the higher place values. That is a specified model, not a universal behaviour of all systems.

Raw image data size is width×height×bits per pixel. Raw audio size is duration×sample rate×bit depth×channels. These calculations exclude metadata and compression, so they are not exact predictions of an arbitrary saved media file.

meaning = bit pattern + representation rules
raw bits ÷ 8 = bytes

See the method

In a made-up unsigned 8-bit field, 250 + 10 = 260 = binary 1 00000100. If this system discards the carry, it keeps 00000100, or 4. Python addition still gives 260. A raw 4 by 3 image at 2 bits per pixel uses 24 bits, or 3 bytes, excluding extra data.

value = 250 + 10
print(value)
print(format(value, "08b"))
print(value % 256)

Predict then reveal

A made-up 4-bit unsigned field keeps only its lowest four bits. Add 13+5. Show full and stored values.

Reveal reasoning

Full result is 18, binary 10010. Four bits can hold 0–15. Keeping the lowest four bits gives 0010, value 2. Ordinary Python 13+5 still gives 18.

A raw 6×5 image uses 2 bits per pixel. Find pixel-data bits and explain a byte-size nuance.

Reveal reasoning

30 pixels×2=60 bits. That is 7.5 bytes worth of bits. Byte-addressed storage needs at least 8 bytes if padded to whole bytes, plus any headers; the raw information amount itself is 60 bits.

Work one step together

Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.

Practice

  1. A reading code is decimal 181. Convert it to exactly eight binary digits and to hexadecimal. Then add decimal 250 and 12. State the full result, whether it fits unsigned 8-bit storage, and the lowest-eight-bit result if this system discards the carry.

Your turn

Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.

Practice

  1. A reading code is decimal 181. Convert it to exactly eight binary digits and to hexadecimal. Then add decimal 250 and 12. State the full result, whether it fits unsigned 8-bit storage, and the lowest-eight-bit result if this system discards the carry.
  2. Build a checker for [0, 181, 255, 256]. Print each value, whether 0 <= value <= 255, its binary text and its hex text. Explain the nine-digit output.
  3. The kiosk uses a raw 8 by 6 image with 4 bits per pixel. It also stores 2 seconds of mono sound at 8000 samples per second with 8 bits per sample. Ignore headers and compression. Calculate each size in bits and bytes. Give one item of metadata needed to decode either file.

Check and explain

A minimum formatting width is not a fixed-width numeric range.

Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.

Show what you know

Why is "four characters always use four bytes" unsafe?

HL challenge when ready

A fixed-width palette must name 17 different colours. What is the smallest number of bits for each palette index?

Week 7 homework

Show working. Keep code and output. Stop at 25 minutes and mark where you reached.

  1. Make one revision card with three short parts. Convert decimal 46 to eight-bit binary and hex. Give the output of True AND NOT True. Name the CPU register holding the next instruction address.
  2. A saved log has values [24, 25, 26]. Write the result of count_high(values, 25). Explain how a local controller can keep working when cloud access fails.
  3. Choose the one revision-map area with the weakest evidence. Create one question and a checked answer for that area. Use only content already taught.

Source workbook pages: 47.

Weekly homework (Word)

Python practice · two short prompts

Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.

A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.

Prompt 1

Compare UTF-8 bytes with displayed text length in a kiosk label.

No imports needed.

Hint and starter code

A kiosk is a dedicated user terminal; encoding maps text to stored bytes.

# A kiosk is a dedicated user terminal; encoding maps text to stored bytes.
label = "温度 24"
print(len(label), len(label.encode("utf-8")))
Open this starter in Python playground →
Prompt 2

Check a raw image storage claim by computing the bytes.

No imports needed.

Hint and starter code

This comparison excludes file headers and compression.

# This comparison excludes file headers and compression.
width, height, depth = 16, 16, 8
claimed_bytes = 256
actual_bytes = width * height * depth / 8
print(actual_bytes == claimed_bytes)
Open this starter in Python playground →