A13 of 18
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 2N, the number of different values N bits can hold. The dashed curve is 100.3N, the rule of thumb that ten bits make about a thousand.
  • Slide N 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 N grows?

Predict

A drive holds exactly 1012 bytes. The operating system divides by 230 and calls the result GB. What does it show?

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

N bits can hold 2N different values

Counting from zero, those values run from 0 to 2N−1: 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

210=1024≈103

so every ten bits multiply the count by about a thousand: 220 is about a million, 230 about a billion. Going the other way, one decimal digit is worth about 3.3 bits, since log2⁡10=3.32.

Memory is built from address lines, and N address lines pick out one of 2N 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:

PrefixSymbolValueCompare
kibiKi210 = 1 024kilo, 103
mebiMi220 = 1 048 576mega, 106
gibiGi230 = 1 073 741 824giga, 109
tebiTi240 ≈ 1.0995 × 10¹²tera, 1012

In practice:

  • Drives are sold in decimal units: 1 TB is 1012 bytes.
  • Memory chips and RAM are sized in binary units. A "16 GB" laptop has 16 GiB, 16×230 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 108 bits, or 12.5 MB, each second. Watch the lowercase b.

How many bits do you need? To give M things their own number, you need the smallest N with 2N≥M, which is N=⌈log2⁡M⌉. With 300 sensors, 8 bits give only 256 addresses, so you need 9.

An ADC's step. An analog-to-digital converter with N bits splits its input range into 2N steps. A 12-bit converter reading 0 to 3.3 V has steps of 3.3/4096=0.806 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
  1. Count the steps needed. The range has to split into steps no bigger than 1 mV, so you need at least 5V1mV=5000steps
  2. Try 12 bits. That's too few: 212=4096steps
  3. Try 13 bits. 213=8192 steps is enough, with steps of 5V8192=0.61mV
  4. 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 5V214=0.31mV

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
  1. The file in bytes. A GiB is 230 bytes: 4GiB=4×230bytes=4294967296bytes
  2. The file in bits. Each byte is 8 bits, so it's 34 359 738 368 bits, about 3.44×1010.
  3. Copy time. The link carries 108 bits each second: t=3.44×1010108s=344s a little under 6 minutes.
  4. 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.
  5. 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
  1. Count the addresses. Seventeen lines pick out 217=131072addresses so the chip holds 131 072 bytes.
  2. Binary units. 217210=27=128KiB a round number, which is why memory comes in sizes like this.
  3. 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 106 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 2N 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?

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.