Comet is building a tiny light panel for the Commons desk. It has two small lights, and each light is either on or off.
"On is 1 and off is 0," she explains. "Two lights can show every Q3 code!"
She tries code 1, then 2, then 3. Each one works.
Then she tries code 4, for bike rack. She stares at the two lights.
Wren leans in. "What do you notice?"
"I have run out of lights," Comet says slowly.
Nova hovers over the panel. "Would you like a hint?" she asks. "Count how many different patterns two lights can make."
Comet starts sketching on the back of the code book.
Binary uses only the digits 0 and 1.
Each position has a place value. The place value is the base raised to the power of the position.
Positions are numbered from 0 at the right, going up by 1 for each step to the left.
In binary the base is 2. So the place values from the right are 1, 2 and 4.
| Position | 2 | 1 | 0 |
|---|---|---|---|
| Place value | 4 | 2 | 1 |
To read a binary number, add the place values of every position that holds a 1.
| Q3 code | Binary | Place values added |
|---|---|---|
| 0 | 00 | nothing |
| 1 | 01 | 1 |
| 2 | 10 | 2 |
| 3 | 11 | 2 plus 1 |
| 4 | 100 | 4 |
Two bits can make only four patterns: 00, 01, 10 and 11. Those are the codes 0, 1, 2 and 3.
Code 4 needs a third bit: 100.
In many programming languages, whole numbers get a fixed number of bits. That limits the range of numbers.
Going past the range can cause an overflow error. Comet's two-light panel just hit that limit.
| Statement | True or false? |
|---|---|
| Binary uses only the digits 0 and 1. | ? |
| Positions are numbered starting from 0 at the right. | ? |
| Two bits can store the code 4. | ? |
| A fixed number of bits limits the range of whole numbers. | ? |
Nice work. Tomorrow in Count Lab you will shrink a column and see what can be rebuilt.