Before class · do this at home
Watch, read, then come
CS50x 2026 · Week 0: Scratch by David J. Malan. Watch the lecture on YouTube (you are also enrolled on edX), read the notes, skim the slides. Our lecture builds on it instead of repeating it.
- Have a GitHub account ready (2 minutes). That is all Lab 1 needs; the Lab 1 page has the rest.
- Create a free account at scratch.mit.edu and click Create once so the editor is familiar.
- Bring a laptop if you have one. The lab PCs work too; everything runs in the browser.
Learning objectives
By the end of this week you can:
- 1 Convert small numbers between decimal and binary, and explain why 8 bits can hold 256 values.
- 2 Explain how text (ASCII, Unicode), colors (RGB), images, sound and video are all encoded as bits.
- 3 Define algorithm, and compare linear search with binary search on the phone-book problem.
- 4 Read and write pseudocode with functions, conditions, loops and variables.
- 5 Build Scratch programs that use functions with arguments and return values, loops, conditions, variables, events and custom blocks, and explain abstraction.
- 6 Recognize the same five ideas in a first C program (preview only; C starts in week 3).
★ the wow moment
One hand can count to 31. Eight switches can store every letter you have ever typed.
Counting on fingers the usual way stops at 5. Treat each finger as a bit (down = 0, up = 1) and one hand counts to 31, two hands to 1023. That is the whole trick behind computers: a switch is a bit, 8 switches are a byte, and the byte 01001000 is the letter H. The laptop in front of you has around 100 billion such switches, each smaller than a virus.
What this week is about
This week follows CS50 Week 0: first how computers represent information, then what an algorithm is, then the five ideas behind every programming language, built one block at a time in Scratch. The orange boxes are the Scratch programs we build together in class. Every one of them is downloadable, so you can open it yourself: in Scratch, File → Load from your computer.
| Project | What it shows | File |
|---|---|---|
| hello0 | one function: say | hello0.sb3 |
| hello1 | input, return value, join | hello1.sb3 |
| hello2 | text to speech: the same idea, another function | hello2.sb3 |
| meow0 · meow1 | one sound, then copy-paste three times | meow0.sb3 · meow1.sb3 |
| meow2 | the loop: repeat 3 | meow2.sb3 |
| meow3 | a custom block: meow (abstraction) | meow3.sb3 |
| meow4 | a custom block with an input: meow n times | meow4.sb3 |
| pet0 · pet1 | conditions and events: forever, if touching, video motion | pet0.sb3 · pet1.sb3 |
| oscartime 1–6 | a game built up in six steps: sprites, if … else, random, custom block, a variable score | 1 · 2 · 3 · 4 · 5 · 6 · full |
| Ivy’s Hardest Game 0–2 | many sprites, or, custom blocks reused | Harvard 0 · 1 · 2 · full |
| Whack-a-Mole | broadcasts, repeat until, several variables | whack-a-mole.sb3 |
Part 1 · What is computer science?
Picture a box. A problem goes in on the left, a solution comes out on the right, and the box in the middle is what this whole course is about. But before we can say anything about the box, we need to agree on how the things going in and coming out are written down. We use words, numbers and pictures. A computer has only electricity, which is either flowing or not.
Part 2 · Representation: everything is bits
Unary, decimal, binary
How high can you count on one hand? Five, if each finger is one unit. That is unary. Now treat each finger as a bit: down is 0, up is 1. Suddenly one hand counts to 31, and two hands to 1023. That is not a trick, it is place value, and it is the whole secret of the machine in front of you.
In decimal we have ten digits, and each position is worth ten times the one to its right (1, 10, 100). A transistor is a switch, on or off, so a computer has two digits, and each position is worth two times the one to its right (1, 2, 4, 8, …).
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | decimal |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 2 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 5 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 73 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 255 |
A single binary digit is a bit; eight of them are a byte; a byte holds 2⁸ = 256 values, 0 through 255. Click the bits, then type your name:
Click the bits of one byte
decimal
0
hex
0x00
ASCII
·
Place values from the left: 128 64 32 16 8 4 2 1. Turn on 64 + 8 + 1 and you get 73, which ASCII calls I.
Text: ASCII and Unicode
Bits are just numbers. To store letters we need an agreement, and the 1963 agreement is ASCII: 65 is A, 66 is B, 97 is a, 48 is the character 0, 32 is a space. So what does 72 73 33 say? Look it up in the table: H, I, !.
ASCII has 128 characters, enough for English and little else. Unicode extends the same idea to about 150 000 characters, every writing system and every emoji, stored as 1 to 4 bytes per character in UTF-8: ş is two bytes, 😂 (code point 128 514) is four. Every emoji you have ever sent was a number.
Color, images, sound, video
- A pixel is three bytes, red, green, blue, each 0–255. (255, 255, 255) is white, (0, 0, 0) black, (255, 0, 0) red. Zoom into any emoji far enough and the squares appear. “Enhance!” in crime shows is impossible: there is nothing behind the bytes.
- An image is a grid of pixels plus a header; a video is many images per second; sound is a wave sampled 44 100 times a second, each sample a number.
- Programs are bits too, instructions the processor understands. We meet them in week 3.
The notebook at the bottom of this page draws a pixel-art smiley from a grid of numbers. Open it in Colab after class.
Part 3 · Algorithms
The classic example: find John Harvard in a 1 000-page phone book.
- Page by page: correct, up to 1 000 steps. Linear search.
- Two pages at a time: twice as fast, but you can overshoot and need a check step. Still linear.
- Open the middle, decide which half, tear the other half away, repeat: 10 steps for 1 000 pages, 20 for a million, 30 for a billion. Binary search, and it only works because the book is sorted.
| Pages | Linear | Binary |
|---|---|---|
| 1 000 | 1 000 | 10 |
| 1 000 000 | 1 000 000 | 20 |
| 1 000 000 000 | 1 000 000 000 | 30 |
Correctness first, then efficiency; the second column is why Google feels instant. Week 5 turns this into a science (Big O).
Pseudocode
Write the algorithm in English with structure, and the vocabulary of every programming language appears by itself:
1 Pick up phone book
2 Open to middle of phone book
3 Look at page
4 If person is on page
5 Call person
6 Else if person is earlier in book
7 Open to middle of left half of book
8 Go back to line 3
9 Else if person is later in book
10 Open to middle of right half of book
11 Go back to line 3
12 Else
13 Quit
| Idea | In the pseudocode | In Scratch (today) | In C (week 3) |
|---|---|---|---|
| function | pick up, open, look at, call | say, play sound, your own blocks | printf, main, your own functions |
| condition | if / else if / else | if … then … else | if (…) { } else { } |
| boolean expression | person is on page | touching, =, <, or | x == 5, n < 10 |
| loop | go back to line 3 | forever, repeat, repeat until | while, for |
| variable | (the current page) | orange variable blocks | int page = 500; |
Keep this table in mind for the rest of the page: every Scratch program below is one or two rows of it.
Part 4 · Scratch: the five ideas, one block at a time
Scratch is a block language from MIT. You drag blocks instead of typing, so there are no syntax errors, and we can concentrate on the ideas. Open scratch.mit.edu → Create. Three areas: blocks on the left, scripts in the middle, the stage on the right. Colors are categories: Motion, Looks, Sound, Events, Control, Sensing, Operators, Variables, My Blocks.
What Scratch taught you, in one list
- Functions with arguments (
say hello) and return values (answer,join). - Loops:
repeat n,forever,repeat until. - Conditions on boolean expressions:
if touching … then … else,and,or,not. - Variables:
set score to 0,change score by 1. - Events: green flag, key pressed, sprite clicked, broadcast received.
- Abstraction:
make a block, with or without inputs; reuse across sprites.
Part 5 · Where this goes
The same program, twice:
when green flag clicked
say [hello, world]
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
}
main is the green flag, printf is say. The semicolon ends a statement; the braces group statements into a block. Next week we type this ourselves, and every block you dragged today gets a text spelling. Not in today’s lab, though: today’s lab is all Scratch and bits.
Summary
- Computers hold only bits. Numbers, text, color, sound, images and programs are all bits under an agreement (binary, ASCII/Unicode, RGB).
- 8 bits = 1 byte = 256 values; n bits give 2ⁿ values.
- An algorithm is a precise procedure; binary search needs a sorted input and takes about log₂ n steps. Pseudocode is how we design before we code.
- Five ideas in every language: functions, conditions (on booleans), loops, variables, events; plus abstraction (custom blocks) to manage size.
- The lab starts at 15:00: Lab 1 · Hello, Scratch. You can begin before the instructor arrives.
In industry
-
Unicode and the emoji you sent today
Text is bytes under an agreement. ASCII (1963) had 128 characters; Unicode has about 150 000 and is maintained by a consortium where Apple, Google and Microsoft vote on new emoji. 😂 is code point 128 514, four bytes in UTF-8.
-
Color on every screen
Every pixel is three bytes, red, green and blue, 0–255 each. #FF0000 in a designer's CSS, (255, 0, 0) in a game engine, and the LEDs in your phone all mean the same three bytes.
-
Compression is why video works
A minute of raw 1080p video is about 9 GB. Netflix sends you a few dozen megabytes. The difference is algorithms that find repeated bits and throw away what your eye cannot see.
-
Scratch is real
Block languages are how Lego robots, many industrial PLCs and Apple's Shortcuts are programmed. The ideas are identical to text languages; only the typing is missing.
Lab 1: Hello, Scratch
Make your own copy of the lab on GitHub, rebuild the meow program with a custom block, build a small Scratch project of your own, and answer seven questions about bits. No C yet. Scratch · due Fri, Oct 2 · 23:59 · 10 points · open now Open lab instructions →Week 2 · Explore: bits, bytes, ASCII and pixels
Read it here, or open it in Colab: it writes, compiles and runs C right in the browser.
Go deeper
- CS50x 2026 · Week 0 notes · The written version of the lecture; excellent for review.
- CS50x 2026 · Week 0 source code (Scratch Studio) · Malan's own projects, online.
- ASCII table · Find your initials in binary.
- Unicode character table · Every character, its code point and its bytes.
- Code, by Charles Petzold (book) · Chapters 1–10: from Morse code to bytes. Free interactive companion site.
Tags:binarybitsbytesASCIIUnicodeRGBalgorithmbinary searchpseudocodeScratchabstractionfunctionsloopsconditionalsvariablesevents