StudyCorner
Back

Computing and the Command Line · Course 4 of 4

How Computers Work

The ideas underneath everything in the Shell, Git, and Linux courses, tried out at the command line. How numbers and text become bits; how logic gates add and remember; what a CPU does with instructions and why memory speed matters; what the operating system does for every program; the data structures and algorithms programs are built from, and how to tell fast from slow; how computers talk over networks; and what no computer can ever do.

24 lessons ~4 h 8 units

0 of 24 done
Start learning
Unit 1

Bits and Numbers

3 lessons · 22 min

  1. 1 Binary and Hexadecimal You plug in a new drive sold as 1 terabyte, and your computer reports about 931 gigabytes. Where did the rest go? Computers store everything as bits, signals with two states. Place value in decimal and binary, counting in binary, bytes and words, and how n bits give 2^n values. Hexadecimal as shorthand for… 8 min Next up
  2. 2 Text as Numbers A shell script written on Windows fails on Linux with a confusing error, though the text looks identical. What’s the usual cause? Text is stored as numbers too. ASCII's 128 characters, one byte each; Unicode's code points for every writing system, written U+00E5; and UTF-8, which stores ASCII as before and everything else in… 7 min Next up
  3. 3 Integers, Overflow, and Floating Point A program holds a whole number of about 9 quadrillion as a floating-point value and adds 1 to it. What happens? Real hardware stores numbers in a fixed number of bits, and that has consequences. Unsigned ranges for 8, 16, 32, and 64 bits; two's complement, how negative numbers are stored and negated… 7 min Next up
Unit 2

Logic and Circuits

3 lessons · 23 min

  1. 4 Boolean Logic and Gates Shift every bit of a binary number one place to the left, putting a 0 on the right. What happens to the number? Logic gates are tiny circuits of a few transistors that compute on bits. AND, OR, and NOT, with their truth tables; NAND, NOR, and XOR; why AND, OR, and NOT can build any circuit, and so can NAND… 7 min Next up
  2. 5 Adding with Gates An adder circuit for 4-bit numbers, which can hold values up to 15, adds 9 and 9. What does it put out? Addition, the most basic thing a processor does, built from gates. The truth table for adding two bits gives a half adder, an XOR and an AND; a full adder adds the carry from the next column; and… 8 min Next up
  3. 6 Memory from Feedback Your computer’s main memory stores each bit as a tiny electric charge. What must it keep doing, even with the power on, to hold its data? Gates compute, but they don't remember: their output depends only on their inputs now. Wiring two NAND gates so each feeds the other creates a loop that holds its own output, an RS latch, one bit of… 8 min Next up
Unit 3

Inside the CPU

3 lessons · 20 min

  1. 7 Instructions and the Fetch-Execute Cycle A one-line C function that returns a + 2 is compiled for an ordinary PC processor. How many machine instructions might that one line become? Almost every computer follows the von Neumann design: a CPU, made of a control unit and a processing unit, and a memory that holds the program's instructions and its data side by side. Instructions… 7 min Next up
  2. 8 The Clock, Pipelines, and Cores The computer pioneer Grace Hopper used to hand out lengths of wire about 30 centimeters long. What did each one show? A clock keeps the CPU in step: each tick starts the next stage, and gigahertz means billions of ticks a second. Why clock speed alone doesn't tell you how fast a processor is; pipelining, which… 6 min Next up
  3. 9 The Memory Hierarchy Scale computer time up so that reading a value from a CPU register takes one second. About how long would a round trip to a server across the internet take? No storage is both fast and big, so computers stack several: registers, caches, main memory, SSDs and hard disks, the network, each step bigger, cheaper, and slower, from under a nanosecond to… 7 min Next up
Unit 4

The Operating System

3 lessons · 39 min

  1. 10 Processes and Scheduling You time a command that does nothing but wait one second and then exit. How much processor time does it use? The kernel turns programs on disk into processes and shares a few CPU cores among hundreds of them, switching every few milliseconds. What a process is; context switches; the Running, Ready, and… 15 min Next up
  2. 11 Virtual Memory Translating every memory address through a table kept in RAM would mean two memory reads for each one a program asks for. Why doesn’t it in practice? Every process gets its own private address space, code, heap, and stack, as if it had the machine's memory to itself, and every address a program ever sees is virtual. How the kernel and the CPU's… 11 min Next up
  3. 12 System Calls and Files A program writes a million bytes to a file, asking the operating system to write each byte separately. How much slower is that than collecting them and writing big chunks? Programs run in a restricted user mode and must ask the kernel, through a system call, for anything outside their own memory: a trap into kernel mode, a handler chosen from a table set up at boot… 13 min Next up
Unit 5

Data Structures

3 lessons · 36 min

  1. 13 Arrays and Linked Lists A Python list grows as you add items one at a time. Over 40 additions, how many times does it have to move to a bigger block of memory? Two basic ways to keep things in order. An array puts items side by side in one block, so any position is one calculation away, but inserting near the front shifts everything after it; a linked list… 12 min Next up
  2. 14 Hash Tables You run the same Python program twice, and each time it prints a set of the words oak, ash, pine, and elm. Will the words come out in the same order both times? Finding an item in a list means checking item after item; a hash table computes where the item belongs instead, so lookups take about the same time among a million items as among ten. How it works… 11 min Next up
  3. 15 Trees and Graphs Filesystems and databases keep their indexes in search trees. Why do those trees give each node many children rather than just two? Structures for things connected to other things. Trees, with a root, parents, children, and leaves, from the filesystem to git; binary search trees, which find a key by going left or right at each… 13 min Next up
Unit 6

Algorithms

3 lessons · 33 min

  1. 16 Searching and Big-O A program tries every possible subset of 100 items, at a billion steps a second. About how long would it take? Linear search checks every item; binary search, on sorted data, halves the possibilities with each check, so ten million items take 24 checks instead of ten million. Logarithms as repeated halving… 11 min Next up
  2. 17 Sorting Could anyone invent a sort that orders any million items, learning about them only by comparing pairs, in far fewer than about 20 million comparisons? Putting things in order, the most studied problem in computing. Insertion sort, simple and O(n²); merge sort, which splits the list in half, sorts each half, and merges them, in O(n log n); both… 11 min Next up
  3. 18 Measuring Real Programs A program finds repeats in a 40,000-line log by searching a list of every line seen so far. Swapping that list for a set, which is built for fast lookups, makes it how much faster? Big-O predicts how time grows; only measuring tells you where a real program spends it. Timing whole programs with bash's time and GNU time; timing small pieces of Python with timeit and reading its… 11 min Next up
Unit 7

Networks

3 lessons · 34 min

  1. 19 Layers and Packets A web request crosses five routers on its way to a server. How many of those routers read the TCP part of each packet? Why the internet chops everything into packets instead of holding a line open like a phone call; Paul Baran at RAND and Donald Davies at NPL, who reached the idea separately; the ARPANET's first… 12 min Next up
  2. 20 IP, TCP, and DNS In October 1986, data between two Berkeley labs 400 yards apart slowed from 32,000 bits a second to 40. What did it? The three protocols under nearly everything. IPv4 addresses and prefixes, with a /22 mask worked bit by bit; private ranges and the NAT box that gives a whole house one public address, and why IANA… 11 min Next up
  3. 21 HTTP and the Web Browsers in the early web often opened several connections to the same website at once. Why? Tim Berners-Lee's 1989 proposal at CERN, which he called Mesh, and the NeXT cube labelled DO NOT POWER IT DOWN that served the first website; a raw HTTP exchange with info.cern.ch read line by line… 11 min Next up
Unit 8

Limits of Computation

3 lessons · 36 min

  1. 22 Algorithms and Turing Machines Turing’s 1936 machine can only read one square of tape, write a symbol, and step left or right. Given unlimited time and tape, what can a laptop compute that it can’t? Hilbert wanted a mechanical method to decide any statement of logic, and before anyone could prove there wasn't one, someone had to say exactly what a method is. Turing's 1936 answer, read from his… 12 min Next up
  2. 23 The Halting Problem Could someone write a perfect checker that reads any program, with its input, and says whether it will ever finish? No program can look at every other program and say whether it will ever finish. Turing's own 1936 argument, which was about machines that stop printing digits, then the modern proof laid out step by… 12 min Next up
  3. 24 Easy and Hard Problems A route planner needs the shortest walk through about 80,000 stops. Checking every possible order would take forever. What is the best that has actually been done? Some problems are solvable but take longer than the universe has. P, the problems solvable in polynomial time, from sorting to shortest routes to primality; NP, the problems whose answers are easy… 12 min Next up