Now let's use every earlier chapter together. You type Hi π into StudyBuddy and press Save.
βββββββββββββββ 1. key press ββββββββββββββββ 2. becomes a βββββββββββββββ
β Keyboard β βββββββββββββββββΆ β Operating β βββββββββββββββββββΆβ StudyBuddy β
βββββββββββββββ electrical β system β "key event" β process β
signal ββββββββββββββββ for the app β (in RAM) β
ββββββββ¬βββββββ
β
3. app stores the text as UTF-8 bytes in RAM: 48 69 20 F0 9F 98 80 β
βΌ
βββββββββββββββ
4. CPU runs the app's instructions (fetchβdecodeβexecute), β CPU β
pulling those bytes through cache β + caches β
ββββββββ¬βββββββ
β 5. "Save"
βΌ
βββββββββββββββ
6. the 7 bytes are written to the SSD, where they survive β SSD β
power-off βββββββββββββββ
7. to show the score, the app turns 200 into the characters "2","0","0",
picks colour #FF8800, and the graphics hardware lights each pixel's
red/green/blue parts β you see an orange "200"Walk through it:
Keyboard β electrical signal. Pressing
Hcloses a tiny circuit. The keyboard sends a code for "the H key".Operating system β app. The operating system (next file) receives it and delivers a "key pressed" message to the program that's in front β StudyBuddy.
Text becomes bytes (Chapter 4.3). The app stores
Hi πas 7 UTF-8 bytes somewhere in RAM, at some memory address (Chapter 7).The CPU does the work (Chapter 5). Every step β "add this character", "redraw this line" β is the app's instructions (Chapter 8) running through fetchβdecodeβexecute, with data pulled into cache (Chapter 6).
Save is pressed. The app asks the operating system to write the bytes to a file.
Bytes reach the SSD (Chapter 6). Now they survive power-off.
The score appears. The number 200 is stored as binary
1100 1000(Chapter 2). To show it, the app converts it into the characters2,0,0(Chapter 4.3), and draws them in colour#FF8800(Chapter 3) β pixels with red 255, green 136, blue 0 (Chapter 4.4).
The number 200 and the text "200" are different things. The number is 1 byte (C8). The text is 3
bytes (32 30 30 in ASCII/UTF-8). Converting between them is called parsing (text β number) and
formatting (number β text). You'll do this constantly: every web form, every API request, every
file you read.
Check yourself
3 questionsIn the trip above, which step makes the note survive a power cut?
Show answerHide answer
Step 6, writing the bytes to the SSD (persistent storage). Before that they were only in RAM.
How is the number 200 stored differently from the text "200"?
Show answerHide answer
The number is one byte 0xC8 (binary 1100 1000); the text is three character bytes
0x32 0x30 0x30.
What did the operating system do in this trip? (We'll go much deeper in the next file.)
Show answerHide answer
It passed the key press to the right program, loaded the program into RAM, and handled writing the file to disk.