Article
Bytes and how many values bits can hold
A game lets you choose one of 4 hair colours, and it must remember your choice. One bit is not enough, because one bit holds only two values. So how many bits does the game need? Once you know how to count the values that bits can make, you can answer this kind of question quickly.
A byte is eight bits
A byte is a group of 8 bits. Computers often work with bits in groups of eight, so the byte is a basic unit for the size of data.
One byte: 0 1 0 0 0 0 0 1 (8 bits)
Two bytes: 0 1 0 0 0 0 0 1 1 0 0 1 0 1 1 0 (16 bits)To find the number of bits, multiply the number of bytes by 8.
How many values can bits make?
One bit can make 2 values: 0 and 1.
Now take two bits. Write every pattern, keeping the first bit and trying both values for the second:
00 01 10 11That is 4 patterns. Every time you add a bit, each old pattern can end with a 0 or with a 1. So each new bit doubles the number of patterns.
| Number of bits | Patterns | Number of values |
|---|---|---|
| 1 | 0, 1 | 2 |
| 2 | 00, 01, 10, 11 | 4 |
| 3 | 000, 001, 010, 011, 100, 101, 110, 111 | 8 |
| 4 | (16 patterns) | 16 |
The rule: n bits can make 2 × 2 × … × 2 values (n twos multiplied together). We write this as 2^n. A byte has 8 bits, so it can make 256 different values.
Use the widget to see the count for 8 bits.
Pattern 00000000 is one of 256 different patterns 8 bits can make (28).
Check your understanding
How many different values can 6 bits make?
How many bits do I need?
Now turn the question around. You have a number of choices to store, and you want the smallest number of bits that is enough. Make a list of the values that 1, 2, 3, … bits can make, and stop at the first number that is at least as big as the number of choices.
Finding the fewest bits
Count the choices
for example 12 clubs
List 2, 4, 8, 16...
the values that 1, 2, 3, 4... bits make
Find the first one that is big enough
at least as big as the choices
Use that many bits
16 is the first, so 4 bits
Our hair-colour game has 4 choices. Two bits make 4 values. That is exactly enough, so the game needs 2 bits.
Worked example: school clubs
A school app has 12 clubs, and each student's club is stored as a pattern of bits. How many bits are needed?
| Bits | Values | Enough for 12? |
|---|---|---|
| 3 | 8 | No, 8 is less than 12 |
| 4 | 16 | Yes, 16 is at least 12 |
The answer is 4 bits. Four of the 16 patterns are never used, and that is fine. You never use fewer bits than you need, and you do not round down.
Check your understanding
A zoo app stores which of 20 animals a visitor chose, using a pattern of bits. What is the fewest number of bits that can do this?
Common mistakes
- Thinking 8 bits make 8 values. 8 is the number of bits. The number of values is 2 × 2 × … (eight times), which is much bigger.
- Adding instead of doubling. Adding one bit does not add one more value. It makes twice as many.
- Rounding down. If 3 bits make 8 values and you need 12, you cannot use 3 bits. Go up to the next number of bits.
- Confusing bit and byte. A byte is 8 bits, so a byte is bigger.
On the exam
Two questions come up often. First, "how many different values can n bits represent?" Second, "what is the fewest number of bits needed for a given number of choices?" Check your answer by listing 2, 4, 8, 16, 32, 64, … and finding the first number that is big enough.
Key words
Byte: a group of 8 bits.
Bit pattern: one particular sequence of 0s and 1s, such as 101.
Doubling: each extra bit makes twice as many patterns as before.
2^n: two multiplied by itself n times. It is the number of values that n bits can make.