Programming, problem solving, and algorithms

CPSC 203, 2025 W2

January 14, 2026

Announcements

  • Setup instructions available.

  • Python resources posted to piazza.

  • First examlet signup available.

Learning outcomes

  1. Computers interpret electrical signals as bits, and bits can be used to represent numbers, and numbers can be used to represent colours, which suggests that we can represent virtually anything!

Representation

Today we’re exploring a fundamental question: How do we represent the world as data?

We’ll look at “representation” in two important senses:

  • Technical: How computers encode rich concepts (like colour) as numbers
  • Social: Who is represented in this discipline, and why it matters

Let’s start with something personal and familiar: colour.

Colour interpretation

What’s your favorite colour? Do you have a sense for why it’s your favorite? Does that colour influence your dress/decor/purchases?

Psychological: https://www.buzzfeed.com/mermaidbarbie/which-color-truly-matches-your-personality-24h9koy69s

Cultural: https://en.wikipedia.org/wiki/Color_symbolism

Your turn: Colour—cultural interpretations

Activity—In pairs, choose a colour (primary or secondary) and find something in its cultural symbolism that surprises you. Contradictions are especially interesting. Report your findings to the class (briefly).

05:00

Colour—representation

Close-up of a solid-state drive (SSD) circuit board showing memory chips and connectors.

First, some general questions…

What does data look like to a computer?



Is that enough?

Colour—representation

Can we use bits to represent integers?

3 1 5 7
103 102 101 100
103 102 101 100
23 22 21 20

Your turn: Binary to decimal

Convert these binary numbers to decimal:

Binary Decimal
1010 _______
1101 _______
0111 _______
03:00

Your turn: Thinking about bits

What’s the largest number you can represent with 4 bits? _______


How many bits do you need to represent 120? _______


If I give you one more bit, what happens to how many numbers you can represent?


How high can you count on your fingers? and toes?

03:00

From bits to… everything?

We’ve seen that bits can represent integers.

But integers are just the beginning!

If we can assign numbers to things, we can represent anything:

  • Text (A=65, B=66, …)
  • Sound (amplitude samples)
  • Images (pixel colours)
  • Video (sequences of images)
  • Your favorite song, your family photos, this lecture…

Let’s see how this works with colour.

Colour—representation

Can we use integers to represent colours?

One way: RGB (red, green, blue), where each “component” is in range 0 through 255.

ex. (255, 0, 127) ==

Fun calculator for colour values: https://colorizer.org

How many bits for 256 values? 4 5 6 7 8 9 10

Colour—representation

What colour is


0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1


Easier to read if we use hexadecimal representation:

Each component is represented by 2 hex digits 0123456789abcdef

ex. #674ea7

Colour—hexadecimal

What colour is this 24-bit number?


0110 0111 0100 1110 1010 0111


Converting to hexadecimal: #___________

(Use digits 0123456789abcdef)

Representation: An aside

What do you observe about the following RGB colours?

Red Green Blue
255 0 0
17 0 178
45 0 13
200 0 220
62 0 37
130 0 95

Colour and Code

Make the poppies pop!

A field of red poppies.

PC: https://www.epicgardening.com/spring-wildflowers-from-seed/

Examine each pixel. If its red colour channel is high (over 200, say), then leave it as is. Otherwise, change the pixel to grey by setting all 3 colour channels to the average of their original values.

Colour and Code

Your turn: Change image or boost

Experiment with the code! Try one or more of these:

  1. Find a different image URL and boost a different colour (green? blue?)
  2. Change the threshold value (try 150 instead of 200)
  3. Instead of greying, try inverting: red = 255 - red
  4. What happens if you boost pixels that are LOW in red instead of high?
12:00

What you learned today

You’ve discovered something profound:

  • Computers store everything as bits (0s and 1s)
  • Bits can represent integers (using binary, base 2)
  • Integers can represent colours (RGB: three numbers 0-255)
  • Which means bits can represent images (grids of pixels)
  • And you wrote code to manipulate those images!

From electrical signals → to making poppies pop.