Index / 001 EN
Code: The Hidden Language of Computer Hardware and Software cover

Computer Science

Computer Science

Code: The Hidden Language of Computer Hardware and Software

Charles Petzold

A narrative explanation of how computers work, starting from codes such as Morse and Braille and building step by step through switches, relays and logic gates to adders, memory and a working central processing unit. Written for general readers, it explains each layer in prose and diagrams rather than equations, and ends with how software runs on that machine.

Prerequisites: None; no knowledge of electronics, mathematics beyond arithmetic, or programming is assumed.

Difficulty Level
Beginner
Academic Level
Undergraduate
computer organizationdigital logicbinarycpu designhistory of computingpopular science

01 / Reading Guide

Reading Guide

Citation

Petzold, C. (2022). Code: The Hidden Language of Computer Hardware and Software (2nd ed.). Microsoft Press (Pearson).

Chapter Summary

The second edition has 28 chapters, about 460 pages before the index, and a preface dated May 2022. It is one continuous argument rather than a set of independent topics: codes lead to switches, switches to relays and logic gates, gates to adding circuits and memory, and those parts are finally assembled into a working central processing unit. Petzold's own account of the revision explains that the first seventeen chapters follow the first edition closely (with a new chapter on clocks), while the CPU chapters that follow are new. Circuit diagrams marked with an icon can also be explored as animated, interactive versions on the free companion website, CodeHiddenLanguage.com.

Chapters 1–3: Best Friends; Codes and Combinations; Braille and Binary Codes

The book opens with the idea of a code. According to the index, the first two chapters work with Morse code, and Chapter 3 turns to Braille, a code built from the presence or absence of raised dots. Together they establish that information can be carried by combinations of two-way choices.

Chapters 4–8: Anatomy of a Flashlight; Communicating Around Corners; Logic with Switches; Telegraphs and Relays; Relays and Gates

The hardware thread begins with a battery, a bulb and a switch. Chapter 6, one of the two sample chapters published by Pearson, starts with Aristotle's syllogisms and George Boole's algebra of classes, works through a pet-shop example in which a customer's wishes become a Boolean expression, and then shows that switches wired in series behave like AND and switches in parallel like OR. Chapter 7 introduces the telegraph relay, and Chapter 8, at 26 pages one of the longest in the book, wires relays into logic gates, including NAND and NOR.

Chapters 9–11: Our Ten Digits; Alternative 10s; Bit by Bit by Bit

These chapters explain number systems: decimal, then other bases, ending with binary and the bit. Petzold notes that Chapter 10 closes with two circuits that encode and decode octal numbers, so the gates of Chapter 8 are not forgotten. The second sample chapter, Chapter 11, finds bits in everyday life: the lanterns in the ride of Paul Revere, film verdicts, the parachute of the Perseverance rover, the Universal Product Code with its parity checking, and a QR code decoded step by step.

Chapters 12–13: Bytes and Hexadecimal; From ASCII to Unicode

The byte and hexadecimal notation are introduced earlier than in the first edition. Chapter 13 covers character encodings from early telegraph codes to ASCII and then Unicode, with several pages on the UTF-8 transformation format and on what goes wrong when the wrong character set is assumed.

Chapters 14–16: Adding with Logic Gates; Is This for Real?; But What About Subtraction?

Gates are combined into circuits that add binary numbers. Chapter 15 supplies historical background and argues that adding with transistors is in principle the same as adding with relays; the website demonstrates lookahead-carry logic. Chapter 16 handles subtraction.

Chapters 17–19: Feedback and Flip-Flops; Let's Build a Clock!; An Assemblage of Memory

Feedback makes circuits that remember: the flip-flop. The new Chapter 18 uses them to build a binary-coded-decimal clock with several kinds of numeric display. Chapter 19 assembles flip-flops into addressable memory.

Chapters 20–24: Automating Arithmetic; The Arithmetic Logic Unit; Registers and Busses; CPU Control Signals; Loops, Jumps, and Calls

The core of the second edition. Chapter 20 lets codes stored in memory control an adding machine. Chapters 21–24, all new, build a CPU that implements more than half the instruction set of the Intel 8080: an arithmetic logic unit, a register array connected by busses, the control signals that sequence each instruction, and conditional jumps, which make the machine Turing complete. Chapter 24 also discusses calls, returns and bit shifting without implementing them.

Chapters 25–28: Peripherals; The Operating System; Coding; The World Brain

The last chapters complete the computer and its software. Chapter 25 deals with video displays, touch screens and analog-to-digital and digital-to-analog converters. Chapter 26 covers the operating system and graphical interfaces. Chapter 27 discusses programming languages, using JavaScript as the language readers can try in a browser, and also covers how numbers such as floating-point values are stored. Chapter 28 traces ideas of a global information network from H. G. Wells, Vannevar Bush and Ted Nelson, then explains how bits travel by modulation and how a browser fetches pages with HTTP.

Key Concepts

Chapters 1–11: Codes, Switches and Numbers

  • Binary code: representing information by combinations of two distinguishable states, as in Morse code and Braille.
  • Boolean algebra: Boole's algebra of classes, reinterpreted as logic with AND, OR and NOT and with values 0 and 1.
  • Series and parallel circuits: switches wired one after the other realise AND; side by side they realise OR.
  • Relay and logic gate: an electrically operated switch, and the gates (including NAND and NOR) built from such switches.
  • Bit: the smallest unit of information, a choice between two possibilities.

Chapters 12–19: Data, Arithmetic and Memory

  • Byte and hexadecimal: eight-bit units and the base-16 notation used to write them.
  • ASCII, Unicode and UTF-8: character encodings, from a 7-bit table to a universal one with variable-length encoding.
  • Adder: a circuit that adds binary numbers from gates; subtraction follows from it.
  • Flip-flop: a circuit with feedback that stores one bit; many of them, with addressing, form memory.

Chapters 20–28: The Processor and Beyond

  • Arithmetic logic unit: the part of a CPU that performs arithmetic and logical operations.
  • Registers and busses: small fast stores inside the CPU and the shared pathways that move data among them.
  • Control signals: the signals that decode an instruction and coordinate the CPU's parts to carry it out.
  • Conditional jump: the instruction that makes the machine able to loop and decide, and hence Turing complete.

Critical Analysis

Strengths

  • One idea at a time, without gaps. The preface states the aim of starting from very simple concepts and climbing to a deep understanding of digital computers, using the language and symbols of engineers rather than piling up metaphors. The sample chapters bear this out: Chapter 6 moves from syllogisms to Boolean expressions to real switch circuits without assuming any background.
  • A real CPU rather than a sketch. Petzold explains that he rewrote the second half because the first edition jumped from simple stored codes to the instruction sets of 1970s microprocessors and asked the reader to take too much on trust. The new Chapters 21–24 build the processor gate by gate, which few general-audience books attempt.
  • Concrete, current examples. Chapter 11 decodes a UPC barcode and a QR code bit by bit, and the second edition expands Unicode coverage to several pages and replaces ALGOL with JavaScript, which readers can run in a browser.
  • Interactive diagrams. The companion website animates the key circuits, so readers can watch current flow through adders, flip-flops and the clock instead of only imagining it.

Limitations

  • Demanding in the middle. The preface warns readers who feel they are drowning to "come up for air", and Petzold writes that readers who find Chapters 21–24 frightening may prefer to skip them. These chapters are long (20–24 pages each) and detailed.
  • No exercises. The sample chapters contain no problem sets, so a student must create practice for themselves, for example by building the circuits in a simulator.
  • Simplified, historical hardware. The CPU implements a subset of an Intel 8080 from the 1970s; modern topics such as pipelining, caches or multicore processors are outside the book's scope.
  • A brief view of networking. The final chapter on the Internet is short by the author's own account; he hoped someone else would write a comparable book about the Internet.

Where It Fits in the Course

Code is the gentlest entry point to the computer architecture course: a narrative for readers with no electronics or programming background. Nisan and Schocken's The Elements of Computing Systems covers similar ground from gates to a working computer, but as a sequence of projects in which students build each layer with supplied simulators; reading Petzold's Chapters 6–24 first makes those projects easier to approach, or they can be read side by side. Harris and Harris's Digital Design and Computer Architecture, RISC-V Edition is the textbook treatment of the same journey, with hardware description languages and a pipelined RISC-V processor.

Bryant and O'Hallaron's Computer Systems: A Programmer's Perspective looks at the machine from the programmer's side (data representation, machine code, memory and processes) and is a natural next step after Chapters 12–13 and 26–27. Hennessy and Patterson's Computer Architecture: A Quantitative Approach and Shen and Lipasti's Modern Processor Design deal with the performance techniques of modern processors, which assume a computer organization course and go far beyond this book.

How to Use This Book

The book suits beginning computing students who want an intuitive picture before a hardware course, students from other disciplines, and programmers who have never looked below their programming language. It needs no prerequisites beyond arithmetic.

  • Read in order. Each chapter depends on earlier ones, and the chapter on gates and the chapters on number bases come together in the adders of Chapter 14.
  • Core path: Chapters 1–20 give the full route from codes to stored-program arithmetic.
  • The CPU chapters: Chapters 21–24 are the most valuable part for an architecture course and the hardest. Read them slowly, with the website open, and trace each control signal by hand.
  • The finish: Chapters 25–28 are lighter and can be read quickly; Chapter 27 is a good bridge to a first programming course.

Because there are no exercises, active reading matters: redraw the circuits, follow the animations on CodeHiddenLanguage.com, and, if possible, build the gates and adders in a free logic simulator or in the projects of The Elements of Computing Systems. The publisher's errata page lists corrections and replacement figures.