Lesson 2: Letters and Pictures in Bits — ASCII Text and Bitmap Pixels

Time: 50 minutes

Unit: Binary, Pixels, Logic Gates, and Packet Switching | Previous: Lesson 1 | Next: Lesson 3

Goal

Encode and decode text using an 8-bit ASCII lookup table, represent 8 × 8 images as 1-bit and 2-bit bitmaps, and calculate storage unit rates in bits per character and bits per pixel.

Materials

Steps

1. Opening (5 min): If Computers Only Store 0 and 1, Where Are the Letters?

Write the byte 01001000 on the board. Ask: - "In Lesson 1, we decoded 01001000 as the number 64 + 8 = 72. How can a text-messaging app use that exact same byte to display a capital letter instead of the number 72?" - Introduce the idea of a shared codebook (standard encoding): if every keyboard and screen agrees on which number stands for which letter, then storing numbers is enough to store words.

2. Main Activity Part A (15 min): Decoding and Encoding ASCII Text

Show the class how uppercase English letters are mapped in standard ASCII (American Standard Code for Information Interchange):

Character Base-10 Code 8-Bit Binary Character Base-10 Code 8-Bit Binary
(space) 32 00100000 A 65 01000001
! 33 00100001 B 66 01000010
0 (digit) 48 00110000 C 67 01000011
1 (digit) 49 00110001 ... ... ...
? 63 00111111 Z 90 01011010

Point out two helpful patterns: 1. Capital A is 65 (01000001), so the n-th letter of the alphabet has code 64 + n! Since 64 is the 01000000 bit, the last 5 bits directly tell you the letter's position (1 to 26) in the alphabet. 2. Lowercase a is 97 (01100001), which is 65 + 32 — toggling just the 32-bit switches any letter between uppercase and lowercase!

Worked Example 1: Decoding a 3-Byte Word

Decode 01000011 01000001 01010100: - Byte 1 (01000011): 64 + 2 + 1 = 67 (3rd letter) → C - Byte 2 (01000001): 64 + 1 = 65 (1st letter) → A - Byte 3 (01010100): 64 + 16 + 4 = 84 (20th letter) → T Word: CAT (3 characters × 8 bits per character = 24 bits).

3. Main Activity Part B (15 min): Bitmap Grids and Bits-per-Pixel Ratios

Now ask: "How do we turn a grid of tiny squares (pixels) into 0s and 1s?" - 1-Bit Monochrome (1 bit per pixel): Each square uses 1 bit: 0 = white (unshaded), 1 = black (shaded). - Example 8 × 8 icon (64 pixels total at 1 bit per pixel = 64 bits = 8 bytes of raw uncompressed pixel data, excluding any file headers or metadata): - Row 1: 00111100 - Row 2: 01000010 - Row 3: 10100101 - Row 4: 10000001 - Row 5: 10100101 - Row 6: 10011001 - Row 7: 01000010 - Row 8: 00111100 (Students shade the 1s on their 8 × 8 grid to reveal a smiling face!) - 2-Bit Four-Color Palette (2 bits per pixel): What if we want 4 colors (like an early handheld game console: 00 = White, 01 = Light Gray, 10 = Dark Gray, 11 = Black)? - Each pixel now requires 2 bits, so the unit rate doubles from 1 bit per pixel to 2 bits per pixel. - For the same 8 × 8 (64-pixel) grid, raw pixel storage doubles from 64 bits (8 bytes) to 128 bits (16 bytes) (excluding any metadata or compression).

4. Discussion & Student Practice (15 min)

Practice Tasks (2.1 – 2.8)

  1. Task 2.1: Using A = 65, find the base-10 ASCII code and 8-bit binary byte for uppercase E (the 5th letter) and M (the 13th letter).
  2. Task 2.2: Decode the 4-byte ASCII message: 01000100 01000001 01010100 01000001.
  3. Task 2.3: Look at the ASCII table: the character '1' has code 49 (00110001), while the number 1 in Lesson 1 was 00000001. Why does a computer distinguish between the text character '1' and the number 1?
  4. Task 2.4 (Unit Rate — Text): A text file contains 150 characters (including spaces) encoded at a unit rate of 8 bits per character. How many total bits and how many bytes does the text file require?
  5. Task 2.5 (Bitmap Decoding): Draw a 4 × 4 grid and shade the 1s for these four 4-bit rows: Row 1 = 0110, Row 2 = 1111, Row 3 = 0110, Row 4 = 0110. What symbol appears?
  6. Task 2.6 (Color Depth Ratio): An 8 × 8 sprite uses a 16-color palette where each pixel uses 4 bits (0000 through 1111). What is the unit rate in bits per pixel, and how many raw pixel bits (and bytes, excluding headers/compression) are needed for all 64 pixels?
  7. Task 2.7 (Aspect Ratio): A game banner measures 120 pixels wide by 80 pixels tall. Write the width-to-height ratio 120 : 80 in simplest whole-number form. If you scale the banner to 300 pixels wide while keeping the exact same aspect ratio, how many pixels tall must it be?
  8. Task 2.8 (Metadata Reasoning): Suppose you receive a raw stream of 64 bits (0s and 1s) for a 1-bit black-and-white picture, but nobody tells you whether the grid is 8 × 8, 16 × 4, or 32 × 2. Why does the receiver need to know the width and height (whether stored in a file header, sent by a communication protocol, or fixed by a prior external agreement) to display the pixel bits correctly?

Complete Answer Key (Tasks 2.1 – 2.8)

Vocabulary

Differentiation

Safety

No physical hazards in this unplugged lesson.

Teacher notes