A1 · Lesson 3 · Powers of two
Why a 1 TB drive shows up as 931 GB
Plug a brand-new 1 TB drive into a computer and it reports 931 GB. Nobody stole 69 gigabytes. The drive maker and the operating system are counting in different units that happen to share a name. One counts in powers of ten, like every other SI prefix. The other counts in powers of two, because that's how digital hardware addresses memory. An engineer who works with ADCs, memory chips or network links has to keep the two straight.
Play
- The solid curve is , the number of different values bits can hold. The dashed curve is , the rule of thumb that ten bits make about a thousand.
- Slide to 10, 20, 30 and 40 and compare the two counts in the readouts.
- Watch the ratio. Does the rule of thumb get better or worse as grows?
Predict
A drive holds exactly bytes. The operating system divides by and calls the result GB. What does it show?
It shows 931 GB. . The two kinds of giga differ by 7.4%, and the gap grows with every prefix step, as the ratio in the sim shows: 2.4% at kilo, 4.9% at mega, 7.4% at giga and 10% at tera.
Name it
Bits, bytes and the prefixes that count in twos
A bit holds one of two values, 0 or 1. Each extra bit doubles the number of patterns, so
Counting from zero, those values run from 0 to : an 8-bit number goes from 0 to 255, a 16-bit number from 0 to 65 535. A byte is 8 bits.
The number that makes powers of two easy to estimate is
so every ten bits multiply the count by about a thousand: is about a million, about a billion. Going the other way, one decimal digit is worth about 3.3 bits, since .
Memory is built from address lines, and address lines pick out one of locations. So memory sizes come in powers of two, and people started calling 1024 bytes a "kilobyte" because it was close enough. In 1998 the IEC gave the binary multiples their own names, so there's no longer any need to guess:
| Prefix | Symbol | Value | Compare |
|---|---|---|---|
| kibi | Ki | = 1 024 | kilo, |
| mebi | Mi | = 1 048 576 | mega, |
| gibi | Gi | = 1 073 741 824 | giga, |
| tebi | Ti | ≈ 1.0995 × 10¹² | tera, |
In practice:
- Drives are sold in decimal units: 1 TB is bytes.
- Memory chips and RAM are sized in binary units. A "16 GB" laptop has 16 GiB, bytes; memory datasheets have long used the plain prefixes with binary meanings.
- Operating systems differ: some show GiB with the label GB, which is where the missing 69 GB went.
- Data rates are decimal and usually in bits per second: a 100 Mb/s link moves bits, or 12.5 MB, each second. Watch the lowercase b.
How many bits do you need? To give things their own number, you need the smallest with , which is . With 300 sensors, 8 bits give only 256 addresses, so you need 9.
An ADC's step. An analog-to-digital converter with bits splits its input range into steps. A 12-bit converter reading 0 to 3.3 V has steps of mV. That one step is the smallest change it can see, often called one LSB (least significant bit).
Worked example
A pressure sensor puts out 0 to 5 V, and you need to see changes of 1 mV. How many bits does the ADC need?
Show the solution
- Count the steps needed. The range has to split into steps no bigger than 1 mV, so you need at least
- Try 12 bits. That's too few:
- Try 13 bits. steps is enough, with steps of
- Pick a real part. Few converters come with 13 bits. The common sizes are 10, 12, 14 and 16, so in practice you'd pick a 14-bit part, with steps of
Answer it needs at least 13 bits (steps of 0.61 mV). In practice you'd use a 14-bit converter, with steps of 0.31 mV.
Worked example
How long does a 4 GiB file take to copy over a 100 Mb/s link?
Show the solution
- The file in bytes. A GiB is bytes:
- The file in bits. Each byte is 8 bits, so it's 34 359 738 368 bits, about .
- Copy time. The link carries bits each second: a little under 6 minutes.
- Watch the units. The traps are the binary GiB on the file and the lowercase b on the link. Forgetting that a byte is 8 bits would make the answer eight times too small.
- Allow for overhead. A real copy takes a little longer, because the network adds headers to every packet.
Answer about 344 s, a little under 6 minutes.
Worked example
A memory chip has 17 address lines and stores one byte at each address. How big is it?
Show the solution
- Count the addresses. Seventeen lines pick out so the chip holds 131 072 bytes.
- Binary units. a round number, which is why memory comes in sizes like this.
- Decimal units. In decimal units it's 131.1 kB.
Answer the chip holds 131 072 bytes: 128 KiB, or 131.1 kB.
Check
How many different values can a number with 9 bits hold?
Check
A microcontroller has 16 KiB of RAM. How many bytes is that?
Check
A drive sold as 4 TB is plugged into a computer that counts in GiB. How many GiB does it show?
Check
A download runs at 50 Mb/s. How many seconds does a 100 MB file take? Take M as in both, and ignore the protocol's overhead.
Check
A building has 5000 sensors on one network, and each needs its own address. What is the smallest number of address bits that will do?
Check
An ADC with 10 bits measures inputs from 0 to 1.8 V. What voltage does one step stand for? Use steps.
Check
A laptop is listed with 16 GB of RAM and a 512 GB drive. Which is right?
Explain why
Why do memory sizes come in powers of two, while drive sizes don't have to?
A memory chip picks out a location with binary address lines, and lines can name exactly locations. A chip built with a size that isn't a power of two would leave some addresses pointing at nothing, so memory comes in powers of two. A drive is addressed by sector numbers that can count to any total, so its maker is free to sell round decimal sizes.
Practice
Keep practicing
13 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.