Skip to content

Foundations

Numbers & Bits

How computers count — binary, hex, and two's complement — and the bit logic that reads and combines them. The language-neutral foundation the assembly on-ramp stands on, shown running in Sinclair BASIC.

Begin — Unit 01 →

What this is

General Programming taught the first half of computer literacy: everything is instructions. This is the other half: everything the instructions touch is a number — and underneath every number is a row of switches, on or off.

Numbers & Bits teaches the ideas that make the machine legible: that a number can be written in tens, in twos, or in hex and still be the same number; that a byte is eight switches; how a computer writes a minus sign when it has no minus sign; and the bit logic — AND, OR, XOR, NOT, masking and shifting — that lets a program read one switch out of eight or pack eight into one.

As before, each idea appears twice: once in plain pseudocode (the idea, with no language in the way), and once in real Sinclair BASIC (the idea, made to happen). Spectrum BASIC is unusually good at this — it can write a number in binary, and turn a letter into its code, with a single word.

Who it’s for

Anyone heading down into a machine. The BASIC track barely needs this; assembly needs it on every line — hex addresses, bit flags, signed offsets — so this is the foundation the assembly on-ramp stands on. Come here once you’ve met General Programming and you’re ready to leave BASIC behind for the metal.

If you only ever write BASIC, you can skim it. If you’re going to write assembly, this is where hex and bits stop being noise and start being a language you read.

What it is not

This is about what a number is, not what a machine does with one. How the screen draws, how a sound chip sings, what lives at which address — those are the machine’s own story, told concretely when you Meet the Machine, where you can watch a byte become a pixel. Here we stay with the numbers themselves: true on every machine, so taught once, before you pick one.

The shape

  • Counting — why ten is just a habit of having ten fingers, and why the machine counts in twos. A number as a pattern of on/off: the bit, the nibble, the byte.
  • The same number, three ways — decimal, binary, and hex as three spellings of one value; place value; why hex is the convenient shorthand for bits; and why 255, 256, and 65535 turn up everywhere once you know to look.
  • Negatives — how a computer writes a minus sign with no minus sign at all: two’s complement, and the wrap-around that comes with it.
  • Bit logicAND, OR, XOR, NOT as the tools that test and combine switches; masking out one bit; setting and clearing them on purpose.
  • Shifting — sliding the whole row of bits left or right, and why that turns out to be multiplying and dividing by two — the machine’s fastest arithmetic.

By the end, hex won’t read as gibberish and a “bit flag” won’t be a mystery — you’ll hold the number sense every assembly program assumes. From here the road goes down: Meet the Machine, and the assembly that speaks in exactly these terms.

The units

  1. 01Ten Fingers, Two WiresStart →
  2. 02Four Bits at a TimeStart →
  3. 03A Minus With No Minus SignStart →
  4. 04Switch by SwitchStart →
  5. 05Slide the Whole RowStart →
  6. 06Numbers That Aren't WholeStart →