Lesson 3 of 6 · 8 min · 2 hands-on steps
Binary: How Computers Count
Flip real bits and see why everything in a computer is 0s and 1s.
Everything is switches
Inside every chip are billions of tiny switches called transistors. Each one is either off (0) or on (1). One switch is called a bit.
One bit can only say two things. Put bits side by side and they can count, just like digits do in normal numbers.
Try it: click the bits
Binary 00000000 = 0 in decimal
Each bit is worth double the one to its right. 8 bits can store 0 to 255.
How to read binary
In everyday decimal numbers, each place is worth 10× the one to its right (ones, tens, hundreds). In binary, each place is worth 2×: 1, 2, 4, 8, 16, 32, 64, 128.
| Binary | Math | Decimal |
|---|---|---|
0001 |
1 | 1 |
0011 |
2 + 1 | 3 |
0101 |
4 + 1 | 5 |
1010 |
8 + 2 | 10 |
Code can write binary directly. Press Run on this example, then change the numbers and run it again:
Why you care
- 8 bits = 1 byte. File sizes (KB, MB, GB) are counted in bytes.
- Letters are numbers too:
"A"is stored as 65. Emojis use several bytes. - You'll almost never write binary at work, but knowing that everything is numbers underneath makes a lot of programming click later.
🧪 Practice: 2 steps
0 / 2 doneStep 1 of 2 · Make the number 5
In code, you can write binary numbers by starting with 0b. For example 0b11 is 3.
Change 0b0 so the program prints 5. (Use the bit visual above: which bits add up to 5?)
Output appears here. Press Run or Ctrl/⌘ + Enter.
Step 2 of 2 · Count to the max
What's the biggest number 8 bits can hold? Print it using an 8-digit binary number (all ones!).
Output appears here. Press Run or Ctrl/⌘ + Enter.
✅ Check your understanding
What is 0b1000 in decimal?
Why do computers use binary?
Create a free account to track your progress.