Lite / Textbooks / Digital Logic and Computer Architecture / Chapter 1
1. Information as bits
Introduction
A computer never stores "seven" or "red". It stores patterns of two-valued signals, and a code that everyone agrees on gives each pattern a meaning. This chapter starts there: why machines choose fixed steps over smooth values, why every extra bit doubles what you can say, how place value works in base 2, and what happens when a number no longer fits.
Figure 1.1. Every bit doubles the patterns (described in words)
Three columns of boxes. One bit gives 2 patterns (0, 1). Two bits give 4 patterns (00 to 11). Three bits give 8 patterns (000 to 111). A label reads: n bits give 2^n patterns.
Explanation
Built from 5 School lessons. Each part is the lesson's own explanation.
1.1 Analog and digital: smooth worlds, stepped machines
A thermometer's red line can sit anywhere. A digital thermometer shows 21.5 or 21.6, never in between. What did it throw away?
Analog: any value
An analog quantity can take any value in a range: the temperature might be 21.4 °C, 21.43 °C or 21.4372 °C. A clock with sweeping hands, a dimmer switch and the height of water in a bath are analog.
Digital: fixed steps
A digital value can only be one of a fixed list of steps. A digital thermometer that shows one decimal place has steps of 0.1 °C: 21.4, 21.5, 21.6. Turning an analog signal into steps is called analog-to-digital conversion. Smaller steps are more precise but need more storage.
The simplest step: a threshold
The roughest possible conversion has just two steps: yes or no, 1 or 0. Pick a threshold: above it is 1, otherwise 0. A night light turns on below a brightness threshold; a sorting machine calls a part 'red' above a redness threshold. Readings close to the line are where mistakes happen, so engineers test them carefully.
Common mix-ups
Digital is always more accurate than analog.
✓ Digital values are rounded to steps, so some detail is thrown away. They are easier to store, copy and process without errors.
Open the Lite lesson: Analog and digital: smooth worlds, stepped machines
1.2 Bits: how much can two lights say?
A lighthouse can only flash on or off. How many different messages could you send with three lamps?
A bit is one choice
A bit (short for binary digit) is the smallest piece of information: 0 or 1. Inside a machine it could be a switch off or on, a voltage low or high, a hole punched or not, a magnet pointing one way or the other.
Every bit doubles the patterns
1 bit: 2 patterns. 2 bits: 4 (00, 01, 10, 11). 3 bits: 8. 4 bits: 16. n bits give 2 × 2 × … × 2 (n times) = 2ⁿ patterns. That's why 8 bits (one byte) already give 256 patterns, enough for every letter, digit and symbol on a keyboard.
A code gives patterns meaning
Patterns mean nothing until people agree a code. A 2-bit code for a robot might be: 00 = stop, 01 = left, 10 = right, 11 = forward. The same pattern can mean different things in different codes, so the sender and receiver must use the same one.
Common mix-ups
Adding a bit adds 2 more patterns.
✓ Adding a bit doubles the number of patterns: 4 bits give 16, 5 bits give 32.
Open the Lite lesson: Bits: how much can two lights say?
1.3 Counting with only 0 and 1
You count 8, 9, 10 because you have ten fingers. How would you count if you only had two?
Place value, the familiar way
In ordinary decimal numbers each place is worth ten times the one to its right: ones, tens, hundreds. 352 means 3 × 100 + 5 × 10 + 2 × 1. You carry when a place goes past 9.
Place value in base 2
In binary, each place is worth two times the one to its right: 1, 2, 4, 8, 16, 32, 64, 128. Each place holds only 0 or 1. To read 1011, put the place values over the bits: 8, 4, 2, 1. Add the places with a 1: 8 + 2 + 1 = 11.
Counting up
0, 1, 10, 11, 100, 101, 110, 111, 1000… The rightmost bit flips every time. The next flips every 2 counts, the next every 4, the next every 8. It's the same carrying you already know, just carrying at 2 instead of 10.
Common mix-ups
Binary 10 means ten.
✓ Binary 10 means one two and no ones: two. Always check which base a number is written in.
Open the Lite lesson: Counting with only 0 and 1
1.4 Converting: binary to decimal and back
A robot's register shows 1001 1100. Is the motor speed high or low? First you need to translate.
Binary → decimal: add the places
Write the place values above the bits, then add the place values that sit over a 1. For 1001 1100: places 128, 64, 32, 16, 8, 4, 2, 1. The 1s are under 128, 16, 8 and 4. Total: 128 + 16 + 8 + 4 = 156.
Decimal → binary: biggest place that fits
- Find the biggest place value that fits into your number. Put a 1 there.
- Subtract it.
- Repeat with what's left. Any place you skip gets a 0.
22: 16 fits (22 − 16 = 6). 8 doesn't (0). 4 fits (6 − 4 = 2). 2 fits (2 − 2 = 0). 1: 0. So 22 = 10110.
Always check by going back
Convert your answer back: 10110 → 16 + 4 + 2 = 22. ✔ It takes seconds and catches most mistakes. Engineers call this a round-trip check.
Common mix-ups
To convert to binary, just write the decimal digits in 0s and 1s.
✓ Binary is a different place-value system. Use the place values 1, 2, 4, 8… to rebuild the number.
Open the Lite lesson: Converting: binary to decimal and back
1.5 Running out of bits: overflow
In 2014 a video got so many views that YouTube's view counter nearly ran out of room. How can a computer run out of numbers?
The biggest number
With every bit on, n bits hold 2ⁿ − 1. 4 bits: 1111 = 15. 8 bits: 11111111 = 255. The '− 1' is because one of the 2ⁿ patterns is used for 0.
Overflow: wrapping round
Add 1 to the biggest number and every bit carries, but the final carry has nowhere to go. The counter shows all zeros. It's like a car's old mileage counter rolling from 99999 to 00000. The machine doesn't complain: it just shows a wrong answer, which is what makes overflow dangerous.
Choosing enough bits
Engineers ask: what's the biggest value this number could ever reach? Then they pick enough bits, plus a safety margin. A step counter for a day might reach 50,000 steps: 16 bits (up to 65,535) is enough. A counter of all views on a video needs far more. In 2014 YouTube's view counter, a 32-bit number that tops out at 2,147,483,647, was upgraded to 64 bits as one video got close to that limit.
Common mix-ups
A computer can store any number you like.
✓ Each stored number has a fixed number of bits and a maximum. Past it, the count overflows.
Open the Lite lesson: Running out of bits: overflow
Worked examples
Analog and digital: smooth worlds, stepped machines: example 1
A light sensor reads 0 (dark) to 1,000 (bright). The night light rule is: ON if the reading is below 200. Readings are 150, 200 and 640. What does the light do each time?
Solution
150 is below 200: ON. 200 is not below 200: OFF. 640: OFF. The boundary value 200 is exactly where you must decide which side it falls.
Bits: how much can two lights say?: example 1
A robot needs commands for: stop, forward, back, left, right and beep. What is the fewest bits per command?
Solution
6 commands. 2 bits give 4 patterns (too few). 3 bits give 8 (enough, with 2 spare). So 3 bits.
Counting with only 0 and 1: example 1
Read the binary number 10110.
Solution
Place values for 5 bits: 16, 8, 4, 2, 1. Bits: 1 0 1 1 0. Add 16 + 4 + 2 = 22.
Converting: binary to decimal and back: example 1
Convert 37 to binary.
Solution
32 fits (37 − 32 = 5). 16: 0. 8: 0. 4 fits (5 − 4 = 1). 2: 0. 1 fits (0 left). So 37 = 100101. Check: 32 + 4 + 1 = 37 ✔.
Converting: binary to decimal and back: example 2
Convert 0110 1001 to decimal.
Solution
Ones are under 64, 32, 8 and 1: 64 + 32 + 8 + 1 = 105.
Running out of bits: overflow: example 1
A parking-garage counter must count up to 600 cars. How many bits does it need?
Solution
2⁹ − 1 = 511 is too small. 2¹⁰ − 1 = 1,023 is enough. So 10 bits.
Interactive figures, in words
Figure 1.2 from Bits: how much can two lights say?
Use the 4-bit register. Starting from all off, press 'Add 1' over and over and write down every pattern until it wraps back to 0000. How many patterns did you find? Now imagine adding a fifth switch.
The binary switches diagram shows a row of 4 (or 8) switches, each showing 0 or 1. Pressing 'Add 1' repeatedly steps through every pattern: 0000, 0001, 0010, up to 1111, which is 16 patterns for 4 bits, and then wraps back to 0000.
Laboratory
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Silicon Studio: Binary (Silicon Studio stage)
Set switches to make 13, 128 and 255, then predict the pattern for 256 before you try it.
Open on the full site - BUILD: Virtual computer, Level 1 (BUILD level)
Convert the build's register values to decimal by hand, then check each one by converting back.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- A sensor measures distances from 0 to 2 m in 200 equal steps. How big is each step, in centimetres?
Answer it in “Analog and digital: smooth worlds, stepped machines” - A vending machine has 10 buttons. What is the smallest number of bits that can give each button its own pattern?
Answer it in “Bits: how much can two lights say?” - The pattern 10 means 'turn right' to one robot and 'beep' to another. Why?
Answer it in “Bits: how much can two lights say?” - In binary, what is the place value of the 5th bit from the right?
Answer it in “Counting with only 0 and 1” - Convert the 8-bit binary number 10011100 to decimal.
Answer it in “Converting: binary to decimal and back” - Write 7 in binary. Type just the 0s and 1s with no leading zeros (for example, six is 110).
Answer it in “Converting: binary to decimal and back” - An 8-bit counter holds 255 and you add 3. What does it show? (It wraps round after 255.)
Answer it in “Running out of bits: overflow” - What is the smallest number of bits a counter needs to reach 1,000?
Answer it in “Running out of bits: overflow”
Engineering applications
Sensor readings
A microcontroller's analogue-to-digital converter turns a voltage into an integer. A 10-bit converter has 2^10 = 1024 steps, so the bit count sets the smallest change it can notice.
Counters that wrap
An 8-bit counter holds 0 to 255. Add one to 255 and it reads 0 again. Engineers pick widths so a timer or tally cannot wrap during the longest run the machine will ever do.
Watch (optional)
Streaming video uses a lot of data. Everything you need is in the text.
- “Early Computing: Crash Course Computer Science #1” by CrashCourse
- “Representing Numbers and Letters with Binary: Crash Course Computer Science #4” by CrashCourse
- “Binary Numbers and Base Systems as Fast as Possible” by Techquickie
Summary
- Digital systems represent information with a small set of distinct levels, usually two, which makes them tolerant of noise.
- n bits give 2^n patterns; a code assigns each pattern a meaning.
- In base 2 each place is worth twice the place to its right: 1, 2, 4, 8, 16 and so on.
- An n-bit unsigned number holds 0 to 2^n − 1. Results outside that range wrap round (overflow).
Glossary
- Bits and bytes
- A bit is a single binary digit, 0 or 1. A byte is 8 bits. n bits can represent 2^n different values. Field Guide
- Binary place value
- In binary each digit position is worth twice the one to its right: 1, 2, 4, 8, 16 and so on. A number's value is the sum of the place values that hold a 1. Field Guide
- Word size
- A processor's word size is the number of bits it naturally handles in one operation: its register width and usually its main data path. Field Guide
- ADC resolution
- An n-bit analogue-to-digital converter splits its reference voltage into 2^n steps; one step, the least significant bit, is the smallest change it can detect. Field Guide
Project: Design a status code
A delivery robot must report one of 11 states (idle, loading, moving and so on) over a few signal wires. Choose the smallest number of bits that can do it, assign a pattern to every state, and decide what the unused patterns should mean.
Deliverables
- A table of every state with its bit pattern
- A one-line argument for why fewer bits would not work
- A rule for what the receiver does with an unused pattern
Write it up on paper or in your own notes. Lite never stores what you write.
References
- Claude E. Shannon (1948). "A Mathematical Theory of Communication". Bell System Technical Journal 27(3), 379–423. doi:10.1002/j.1538-7305.1948.tb01338.x Link
- David Money Harris and Sarah L. Harris (2012). Digital Design and Computer Architecture, 2nd edition. Morgan Kaufmann.
- Noam Nisan and Shimon Schocken (2021). The Elements of Computing Systems: Building a Modern Computer from First Principles, 2nd edition. MIT Press. Link