Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / How Computers Work

    Quick Reference

    Glossary and cheat sheet for How Computers Work — the page to reread before an interview.

    Extra: Reference7 min read

    Glossary#

    TermPlain meaningChapter
    bitone on/off switch, written 0 or 11
    transistorthe microscopic electronic switch that stores/moves a bit1
    binary (base 2)counting using only 0 and 12
    decimal (base 10)normal human counting with 0–92
    byte8 bits; holds 0–2552
    KB / KiB1,000 / 1,024 bytes2
    overflowa number too big for its space wraps around2
    hexadecimal (hex)base 16; one digit = 4 bits; 0x prefix3
    encodingan agreement for what bytes mean4
    two's complementthe standard way to store negative whole numbers4.1
    floating point / IEEE 754the standard way to store fractions, with tiny rounding errors4.2
    ASCIIthe old 128-character codebook, 1 byte each4.3
    Unicode / code pointthe worldwide character codebook / a character's number in it (U+…)4.3
    UTF-8the way to turn code points into 1–4 bytes; the default everywhere4.3
    mojibakegarbled text from reading bytes with the wrong encoding4.3
    pixelone dot on a screen, stored as R, G, B bytes4.4
    CPU / processorthe part that follows instructions5
    instruction / machine codeone tiny CPU step / the bits encoding it5
    registera super-fast storage slot inside the CPU5
    program counterthe register holding the address of the next instruction5
    clock speed (GHz)billions of CPU ticks per second5
    coreone independent instruction-runner inside the CPU5
    x86-64 / ARMthe two main CPU instruction sets5
    RAMworking memory; fast; lost on power-off (volatile)6
    SSD / HDDpersistent storage; chip-based / spinning disk6
    cache (L1/L2/L3)small, very fast memory in the CPU holding copies of recently used RAM6
    cache linethe 64-byte block copied from RAM to cache at once6
    localityprograms tend to reuse nearby and recent data6
    ns / µs / msbillionth / millionth / thousandth of a second6
    memory addressthe number of one byte's position in RAM7
    pointer / referencea value holding the address of other data7
    little-endian / big-endiansmallest-byte-first / biggest-byte-first order7
    source codethe program as humans write it8
    compiler / interpretertranslates before running / while running8
    bytecode / virtual machineportable intermediate code / the program that runs it8
    JVM / JITJava's virtual machine / its live compiler for hot code8
    CPythonthe standard Python interpreter8
    processa program loaded into RAM and running8
    parsing / formattingtext → number / number → text9

    Cheat Sheet#

    Powers of two to memorise

    Output
      2^8  = 256          2^10 = 1,024 (≈ thousand)     2^16 = 65,536
      2^20 ≈ 1 million    2^30 ≈ 1 billion              2^32 ≈ 4.3 billion

    Conversions

    Output
      binary → decimal : add the position values where the bit is 1   (1101 = 8+4+1 = 13)
      decimal → binary : subtract the biggest power of 2 that fits, repeat
      binary ↔ hex     : group bits in 4s from the right; each group = one hex digit
      bits ↔ bytes     : divide bits by 8  (100 Mbps ≈ 12.5 MB/s)

    Java number limits

    Output
      int   32-bit   ±2.1 × 10^9     → use long when sums can pass ~2 billion
      long  64-bit   ±9.2 × 10^18
      safe midpoint:  low + (high - low) / 2

    Rules

    Output
      never == on floats          compare with Math.abs(a - b) < 1e-9
      never floats for money      integers in the smallest unit, or BigDecimal / Decimal / NUMERIC
      always UTF-8                and declare it at every boundary (files, DB, HTTP)
      characters ≠ bytes          "Hi 😀" = 4 characters, 7 UTF-8 bytes; Java length() = 5

    Latency ladder (roughly)

    Output
      L1 1 ns → L2 4 ns → L3 15 ns → RAM 100 ns → SSD ~50 µs → HDD ~5 ms
      → same-datacentre network 0.5 ms → India↔USA ~200 ms

    Try This Yourself#

    1. Watch overflow happen. In Java (install a JDK, or use an online Java runner), run:

      Java
      public class Main {
          public static void main(String[] args) {
              int x = Integer.MAX_VALUE;
              System.out.println(x + 1);
              System.out.println(0.1 + 0.2);
              System.out.println("Hi 😀".length());
          }
      }

      Explain each output using Chapters 2, 4.2 and 4.3. (The last one prints 5: H, i, space, and two UTF-16 units for 😀.)

    2. See the bytes of text. On a Mac terminal: echo -n "Hi 😀" | xxd. You should see 4869 20f0 9f98 80 — the exact 7 bytes from Chapter 4.3. Try café and find the c3a9.

    3. Measure your memory ladder. Run sysctl -a | grep -E "cachesize|memsize" on your Mac (or check "About This Mac") and write down your L1, L2 cache and RAM sizes next to the table in Chapter 6.