Books Notes

Code: The Hidden Language of Computer Hardware and Software

Charles Petzold

★★★★★ Finished August 2014

The question

Charles Petzold is a programmer and writer best known for teaching a generation of developers to program Microsoft Windows. In 1999 he published Code, a book with a different aim: to explain how computers work to readers with no technical background, without skipping any step. A second edition, substantially revised, appeared in 2022, with an interactive website that lets readers operate the circuits the book describes.

His question is how a machine made of wires and switches can do the things computers do. Most explanations of computing start in the middle, with programming languages or with the parts of a computer as a black box. Petzold starts at the bottom and builds up, so that by the end the reader understands, at least in principle, every layer.

The path through it

The book begins with two children who want to talk to each other at night across the street, and who invent a code using flashlights. From that scene Petzold introduces the idea of a code, a way of representing information with a small set of signals, and shows two historical examples: Morse code, built from dots and dashes, and Braille, built from patterns of raised dots. Both show that rich information can be represented with only two states.

He then turns to electricity, explaining circuits with batteries and lightbulbs, and introduces the telegraph. Telegraph lines over long distances needed relays, devices in which a weak current operates an electromagnet that closes a switch for a stronger current. A relay is a switch controlled by electricity. That is the crucial idea.

Next he introduces binary numbers, showing that any number can be written with only two digits, and the logic of George Boole, the nineteenth-century mathematician who showed that logical reasoning could be expressed as algebra with two values, true and false. In 1938 Claude Shannon showed in his master’s thesis that relay circuits could implement Boolean logic. Petzold walks the reader through that connection, building logic gates, AND, OR, NOT, from relays.

From gates he builds an adding machine, a circuit that adds binary numbers. Then he introduces feedback, wiring a circuit’s output back to its input, which produces oscillators, which keep time, and flip-flops, which remember a single bit. Memory grows from flip-flops arranged in arrays.

With adders, memory and a clock, Petzold builds an automated machine that can follow a sequence of instructions stored in memory, and from that a simple processor. He then explains machine code, assembly language, input and output, the operating system and, in the later chapters, graphics, high-level programming languages and how text, images and sound are represented in binary.

Where it arrives

The book arrives at a full picture of a computer, from the representation of information to the processor that manipulates it. Its central lesson is that complexity comes from layering. Each layer is built from the one below, and each is understandable on its own. A modern processor contains billions of transistors, which have replaced relays, but the principles are the ones Petzold builds with switches and bulbs.

The book also shows how much of computing’s history was a matter of putting old ideas together. Codes, electricity, binary arithmetic and Boolean logic existed long before computers. The insight was to combine them.

What remains open

The book explains how computers work but leaves aside why they have become what they are: the economics, organisations and decisions that shaped computing. It also stops short of the most recent developments, though the second edition updates much of the material. Modern processors include pipelines, caches, parallel cores and specialised units for graphics and artificial intelligence, which build on the same foundations but add layers the book can only point to.

And the book leaves open a philosophical question. If a computer is nothing but switches, what is computation, and what is the relationship between the physical machine and the meaning of what it computes? Petzold’s engineering does not settle that, though it makes the question precise.

What it asks of someone deciding

The book asks whether you understand the layers beneath your decisions. Many people who make decisions about technology work only with its top layers. Knowing even roughly how the layers below work makes it easier to judge what is possible, what is expensive and what is hard. The site’s essays The Universal Machine and the End of the Free Lunch and Machines Inside Machines trace how those layers shaped the industry.

It asks whether complexity in your work is necessary or accidental. Petzold shows that great complexity can be built from simple parts, if each layer is clean. Systems that are confusing at every level usually lack that discipline.

And it asks how you explain hard things. Petzold’s method, starting from what the reader knows and adding one idea at a time, is a model for anyone who needs to make a complex subject understandable.

Read it with

  • The Information James Gleick

    James Gleick's history of information, from talking drums to Claude Shannon.

  • Turing's Cathedral George Dyson

    George Dyson on the building of one of the first stored-program computers.

  • The Innovators Walter Isaacson

    Walter Isaacson on the people who created the digital revolution.

  • Gödel, Escher, Bach Douglas R. Hofstadter

    Douglas Hofstadter on formal systems and meaning, the philosophical depth beneath Petzold's engineering.

Checked against

  1. Charles Petzold, Code, The Hidden Language of Computer Hardware and Software (Microsoft Press, 1999; second edition, 2022).
  2. Charles Petzold, CodeHiddenLanguage.com, the interactive companion to the second edition.
  3. Claude E. Shannon, "A symbolic analysis of relay and switching circuits", Transactions of the American Institute of Electrical Engineers 57, no. 12 (1938), 713–723.

The note paraphrases the book. Any quotation is short and comes from a public-domain edition or a lawful copy. Read the book itself; this is a way in, not a substitute.

Follow the thread

Where this book appears on the site

↑ ↓ to move↵ to open⌘K to toggle