Foundations: how computers work

Bits and bytes, binary and hex, negative numbers, bitwise tricks, floating point, text, memory and how a program runs, explored in C.

  1. 1

    Bits and bytes

    Everything in a computer is stored as bits; eight bits make a byte, and every type has a size in bytes.

  2. 2

    Number systems: binary, octal and hexadecimal

    The same number written in base 10, base 2, base 8 and base 16, and how to convert between them.

  3. 3

    Negative numbers and overflow

    Two's complement stores negative numbers; unsigned numbers wrap around; signed overflow is a bug.

  4. 4

    Bitwise operations

    AND, OR, XOR, NOT and shifts work on single bits: test, set and clear flags, and multiply by powers of two.

  5. 5

    Floating-point numbers

    Why 0.1 + 0.2 is not exactly 0.3: doubles store binary fractions with about 15 significant digits.

  6. 6

    Characters and text

    A character is a small number: ASCII codes, letter arithmetic, and how UTF-8 stores Bangla and emoji in several bytes.

  7. 7

    Memory: addresses, the stack and the heap

    Memory is a long row of numbered bytes; where globals, locals and malloc blocks live, and the byte order of an int.

  8. 8

    How a program runs

    From source code to machine instructions: compiling, linking, the CPU's fetch-decode-execute loop, and the call stack.