Find a course

Module 1: Counting in Different BasesLesson 2 of 1112 min

Counting in Binary and Powers of Two

Count from 0 to 15 in binary, learn the place values 1, 2, 4, 8 and up, and see how many values a given number of bits can represent.

Step 1 of 12Learn

Counting with only 0 and 1

Counting in binary follows exactly the same rule as decimal, just with fewer digits. In decimal you count 0, 1, 2 up to 9, run out of digits and carry. In binary you run out after 1.

So: 0, 1, and then the ones place is full. Write 0 and carry 1 to the next place: 10. That's binary for two. Then 11 (three). Now both places are full, so carry again: 100 (four).

DecimalBinaryDecimalBinary
0081000
1191001
210101010
311111011
4100121100
5101131101
6110141110
7111151111

Look down the binary column and you'll spot patterns. The rightmost bit alternates 0, 1, 0, 1. The next bit alternates every two numbers, the next every four, the next every eight. And every time the number is all 1s (1, 11, 111, 1111), the next number is a 1 followed by all 0s, exactly like 999 rolling over to 1000.

A joke programmers love: "There are 10 kinds of people in the world: those who understand binary and those who don't." Now you're in the first group.

Step 2 of 12Practice · Put in order

Put these binary numbers in counting order, from smallest to largest.

Drag the items, or use the arrow buttons, to put them in order.

  1. 111
  2. 110
  3. 1001
  4. 101
  5. 1000

Step 3 of 12Diagram

Counting from 0 to 7 in binary

Counting from 0 to 7 in binaryProcess diagram: 0 → 1 → 10 → 11 → 100 → 101 → 110 → 111.011011100101110111

Tap a shape with to see more.

0
1

Out of digits already.

10

Carry: two is written 10.

11
100

Both places are full, so carry twice.

101
110
111

Seven: every place is 1.

Step 4 of 12Learn

The binary place values

In decimal, places are worth powers of 10. In binary, they're worth powers of 2. From right to left:

2726252423222120
1286432168421

Each place is worth double the place to its right. Memorize these eight; you'll use them constantly. It also helps to know a few bigger ones: 210 = 1,024, which is close to a thousand and is why computer memory sizes often come in multiples of 1,024, and 216 = 65,536.

The rightmost bit, worth 1, is called the least significant bit (LSB). The leftmost is the most significant bit (MSB), because it carries the biggest value.

A neat property: since only the ones place is odd, a binary number is odd if its last bit is 1 and even if it's 0. You can tell 1011 is odd and 1010 is even without converting either.

Groups of bits have names. One bit is a bit. Four bits make a nibble. Eight bits make a byte, the basic unit for measuring memory and file sizes.

Step 5 of 12Practice · Chart

Binary place values double each step

Tap the place worth 32.

Tap the bar that answers the question, then press Check.

Binary place values double each stepBar chart with 8 categories: 2^0: 1; 2^1: 2; 2^2: 4; 2^3: 8; 2^4: 16; 2^5: 32; 2^6: 64; 2^7: 128.050100150Worth2^02^12^22^32^42^52^62^7Place, from the right1248163264128
Binary place values double each step
Place, from the rightPlace value
2^01
2^12
2^24
2^38
2^416
2^532
2^664
2^7128

Step 6 of 12Practice · Fill in the blanks

Fill in the blanks

Reading from right to left, the first five binary place values are 1, 2, 4, and . A group of 8 bits is called a .

Step 7 of 12Learn

How many values fit in n bits?

Here's one of the most useful facts in computing: n bits can represent 2n different values.

Why? Each bit has 2 options. With 1 bit there are 2 patterns. Add a second bit and each of those patterns can be followed by a 0 or a 1, doubling the count to 4. A third bit doubles again to 8. Every added bit doubles the possibilities.

BitsPatternsRange (starting at 0)
120 to 1
4160 to 15
82560 to 255
1665,5360 to 65,535
32about 4.3 billion0 to 4,294,967,295

Notice the largest value is always 2n − 1, one less than the number of patterns, because one pattern is used for zero. A byte holds 256 values, but the biggest is 255.

You'll see these numbers everywhere once you know them. Why do some old games cap a stat at 255? It's stored in one byte. Why did older internet addresses run short at about 4.3 billion? They're 32-bit numbers. Why do color values go from 0 to 255? One byte per color channel.

Going the other way, to store N different values you need the smallest n with 2n ≥ N.

Step 8 of 12Explore

Doubling with every bit

The curve shows how many values n bits can represent. Drag the slider to choose a number of bits and read the exact counts.

020,00040,00060,000 051015
Different values (2n)
256
Largest value (2n - 1)
255

Step 9 of 12Practice · Work it out

A game stores each player's level in 6 bits, starting at level 0. What is the highest level it can store?

Step 10 of 12Note

Step 11 of 12Practice · Diagram

One hand, five bits

Which single finger raised on its own shows the number 8?

Tap the shape that answers the question, then press Check.

One hand, five bitsParts diagram: Right hand: 0 to 31, Thumb = 1, Index = 2, Middle = 4, Ring = 8, Pinky = 16.Right hand: 0to 31Thumb = 1Index = 2Middle = 4Ring = 8Pinky = 16
Right hand: 0 to 31
Thumb = 1
Index = 2
Middle = 4
Ring = 8
Pinky = 16

Step 12 of 12Practice · Work it out

A school needs a unique code for each of its 300 lockers. What is the fewest number of bits that can give every locker a different code?