Pixel Pictures: Binary Codes on a Grid

← Free Lesson Plans for Teachers

Free Lesson Plan

Grades 4–6Engineering & Coding2 sessions x 45 min2-DA-07

⬇ Download PDF (lesson, student sheets & answer key)

Driving question: How can a computer store a picture using only numbers?

Overview

Students decode three hidden pictures to see how computers store images as numbers. Picture 1 uses binary (1 = filled pixel, 0 = empty). Picture 2 uses run-length codes (counts of empty and filled pixels in a row). Picture 3 uses two-bit codes for four colors. Then students design and encode their own picture for a partner to decode.

Comparing the three codes shows that the same data can be represented in more than one way, and that some codes are shorter for some pictures. It is an unplugged first look at how screens, images, and file compression work.

Standards

CodeStandard
CSTA 2-DA-07 (2017)representing data with different codes

CSTA 2-DA-07 is a grade 6–8 code; grades 4–5 can do the same activity as an early introduction. CSTA codes are from the CSTA K-12 CS Standards (2017); the short labels are our own summaries, not CSTA wording. This lesson has not been reviewed or endorsed by CSTA.

Learning Objectives

Students will:

  • decode binary, run-length, and two-bit color codes into pictures.
  • encode a picture in two different ways.
  • compare codes by length and explain which is better for a given picture.

Materials

Geyer resources for this lesson

Also needed

Vocabulary

WordWhat it means
pixelOne small square of a digital picture.
binaryA number system using only 0 and 1.
bitOne binary digit, 0 or 1.
encode / decodeTo turn information into a code / to turn a code back into information.
run-length codeA code that counts how many of the same pixel come in a row.

Safety Notes

  • No special hazards.

Before You Teach

  • Copy Student Sheets 1-3. Draw an 8 × 8 grid on the board.

Warm-Up (5 min)

  • Zoom in on any digital photo until you see squares. Ask: "What are these squares? How might a computer remember which color each one is?"

Procedure

Session 1: Binary and run-length (40 min)

  1. Model row 1 of Picture 1 on the board: 01100110 means empty, filled, filled, empty, empty, filled, filled, empty.
  2. Students decode Picture 1 (binary) on Student Sheet 1.
  3. Introduce run-length codes: each row lists counts starting with empty pixels. “0, 8” means 0 empty, then 8 filled. Decode Picture 2.
  4. Write row 1 of Picture 2 in binary too, then compare: which code is shorter for this row? Count numbers/digits for both pictures.

Session 2: Color codes and design (45 min)

  1. Two bits make four codes: 00 white, 01 orange, 10 blue, 11 black. Decode Picture 3 on Student Sheet 2.
  2. Students design their own 8 × 8 picture on Student Sheet 3, then write it in binary and in run-length code.
  3. Trade codes with a partner. Decode and compare with the original. Fix any errors.

Differentiation

SupportOn-levelChallenge
• Decode only Picture 1, with every other row done.
• Use a 6 × 6 grid for the design.
• Complete the procedure and student sheets as written.• How many bits would a 100 × 100 picture with 4 colors need? (20,000.)
• Invent a code for 8 colors and explain how many bits each pixel needs (3).

Assessment

  • Check decoded pictures.
  • Check a partner can decode the student’s picture.

Exit ticket: Ask: "Which code is shorter for a picture with long rows of the same color, binary or run-length? Why?"

CriterionBeginningDevelopingProficient
DecodeMany errorsSome errorsAll three decoded correctly
EncodeOne code, errorsTwo codes, some errorsTwo codes, correct
CompareNo comparisonStates which is shorterExplains why with counts

Extensions

  • Explore how a screen mixes red, green, and blue light for each pixel.
  • Middle school follow-up: compare file sizes of the same image saved two ways. Related: Binary Light Messages (Lesson 314).

Student Sheets

Use these sheets in class, or download the PDF for a print-ready layout.

Student Sheet 1

Decode Pictures 1 and 2

Print-ready version in the PDF.

Name: ______________________________   Date: ______________

Picture 1 (binary): 1 = color the square, 0 = leave it blank.

RowCode
101100110
211111111
311111111
411111111
501111110
600111100
700011000
800000000

Picture 2 (run-length): counts of blank, colored, blank, colored… in each row, always starting with blank.

RowCode
10, 8
20, 1, 6, 1
30, 1, 1, 1, 2, 1, 1, 1
40, 1, 6, 1
50, 1, 1, 4, 1, 1
60, 1, 6, 1
70, 8
82, 1, 2, 1, 2

Student Sheet 2

Decode Picture 3 (two-bit color)

Print-ready version in the PDF.

Name: ______________________________   Date: ______________

Each pair of bits is one pixel: 00 = white, 01 = orange, 10 = blue, 11 = black.

RowCode
100 00 01 01 00 00
200 01 01 01 01 00
300 01 01 01 01 00
400 00 01 01 00 00
510 10 10 10 10 10
610 10 10 10 10 10

How many bits does this picture use?

Which picture had the shortest code? Why?

Student Sheet 3

Design and Encode

Print-ready version in the PDF.

Name: ______________________________   Date: ______________

My picture in binary (8 rows):

My picture in run-length code:

Show answer key (for teachers)

Answer Key & Teacher Notes

Answer Key

Picture 1 is a heart; Picture 2 is a robot face; Picture 3 is a sun over water.

  • Picture 3 uses 6 × 6 pixels × 2 bits = 72 bits.
  • Shortest code: Picture 2’s run-length code uses 35 numbers total, compared with 64 binary digits for Picture 1 and 72 bits for Picture 3. Run-length is shorter when there are long runs of the same color (row 1 of Picture 2 is just “0, 8” instead of 11111111), though it can be longer for busy checkerboard rows.
  • Challenge: 100 × 100 × 2 bits = 20,000 bits; 8 colors need 3 bits each.

Need a print-ready copy? The PDF includes the lesson, student sheets, and answer key.

Download the PDF  |  All free lesson plans

Free for classroom use. You may print and copy this lesson for your students. © Geyer Instructional Products. Standards text: CSTA K-12 CS Standards © CSTA.