Skip to content

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

    Computer Basics / How Computers Work

    Bits

    One on/off switch is called a bit (short for "binary digit").

    Chapter 1 of 95 min read

    Start With the Problem#

    You open StudyBuddy (the imaginary study app we use across this whole curriculum — see the root README.md). You type a note:

    Output
    Hi 😀

    You press Save. Your quiz score of 200 appears on the screen in orange.

    Now think about what is actually inside your laptop: metal, silicon (a material made from sand), and electricity. There are no letters in there. No emojis. No numbers. No colour orange. There is only electricity flowing or not flowing through billions of microscopic wires.

    So how does a box of sand and electricity:

    • remember the letter H?

    • store the number 200?

    • show the colour orange?

    • follow instructions — "when Save is clicked, write this note to disk"?

    That is the question this file answers. By the end you will be able to trace Hi 😀 from your keyboard, into the machine's memory, as exact 0s and 1s, and back onto the screen.

    The Plain Picture#

    Imagine a light switch. It has exactly two positions: off or on. No "half on".

    Now imagine you and a friend are in two buildings at night. You agreed beforehand: light on means "yes", light off means "no". With one switch you can send one yes/no answer.

    With two switches you can send more. Each switch is on or off, so together they have 4 combinations:

    Output
      switch A   switch B   meaning we agreed on
      --------   --------   --------------------
        off        off      "stay home"
        off        on       "meet at cafe"
        on         off      "meet at park"
        on         on       "meet at station"

    Notice: we didn't invent a new kind of switch. We just used more of the same simple switch, and agreed what each combination means. That is the entire trick of computing.

    The Real Name#

    • One on/off switch is called a bit (short for "binary digit").

    • We write off as 0 and on as 1.

    • Inside a chip, a bit is stored by a transistor — a microscopic electronic switch with no moving parts. A modern laptop processor has tens of billions of them.

    Under the Hood#

    Why only two states? Why not ten, like our 0–9 digits?

    Electricity inside a chip is never perfectly exact. A wire meant to carry 1.0 volt might carry 0.93 or 1.07 because of heat and interference ("noise").

    • With 2 states, the chip only has to decide "is this closer to 0 volts or to 1 volt?". That is easy and almost never wrong.

    • With 10 states, it would have to tell 0.3 V from 0.4 V. Noise would cause constant mistakes.

    So two states is not a limitation someone forgot to fix. It is the choice that makes computers reliable.

    How many combinations do n bits give? Each extra bit doubles the count:

    Output
      bits   combinations
      ----   ------------
       1        2          (0, 1)
       2        4          (00, 01, 10, 11)
       3        8
       8      256
      16   65,536
      32   4,294,967,296   (~4.3 billion)
      64   ~18.4 billion billion

    The formula is 2ⁿ (2 multiplied by itself n times). Remember 2¹⁰ = 1,024 ≈ one thousand — you will use that shortcut constantly.

    Gotchas

    • A bit has no meaning on its own. 1 could mean "yes", "light on", "the number one", or "this file is read-only". Meaning always comes from an agreement about how to read the bits. Keep this in mind for Chapter 4.

    • "Binary" does not mean "simple". Everything you see on a computer — video, games, AI — is built from nothing but bits plus agreements.

    Check yourself

    3 questions
    1

    Why do computers use 2 states instead of 10?

    Show answer

    Electrical noise makes it hard to tell many voltage levels apart; two levels (low/high) can be told apart reliably.

    2

    How many different combinations can 5 bits represent?

    Show answer

    2⁵ = 32.

    3

    You need to give every student in a school of 1,000 students a unique code made of bits. What is

    the smallest number of bits you need?

    Show answer

    10 bits. 2⁹ = 512 is too few, 2¹⁰ = 1,024 is enough.