awesome-everything RU
↑ Back to the climb

Base CS from zero

Counting in binary

Crux A row of bits encodes a number through place value: each position is worth twice the one to its right. Understanding this doubling principle lets you read and write binary numbers and convert between binary and decimal.
◷ 20 min

You now know that a bit is a single two-state switch — it holds 0 or 1. But a single switch can only answer one yes/no question. How does a row of eight switches encode the number 42, or 200, or 255? The answer is the same trick your pocket calculator uses without telling you: place value. The same principle that makes the digit 3 worth thirty in “32” and three hundred in “307” works in binary — except instead of each place being worth ten times the previous one, it is worth exactly two times.

Goal

After this lesson you can read a binary number by summing its place values, convert any small decimal number to binary by repeated division, and explain why adding one bit always doubles the count of numbers a pattern can represent.

1

Place value: the same idea as decimal, with base 2 instead of base 10. In the decimal system you already know, each position has a weight that is a power of ten: the ones place is 10⁰ = 1, the tens place is 10¹ = 10, the hundreds place is 10² = 100, and so on. A number is just the sum of each digit multiplied by its place weight. In binary the only change is that the base is 2 instead of 10, so the weights are powers of 2: 2⁰ = 1, 2¹ = 2, 2² = 4, 2³ = 8, 2⁴ = 16, and so on. Every binary digit (0 or 1) is multiplied by its place weight and the results are summed.

2

Why each place is worth twice the one to its right. Think about what “carrying” means. When you count up from 0 and reach the limit of what the current place can hold, you carry into the next place. In decimal the limit is 9; in binary the limit is 1 — the very next value after 1 overflows and must be carried. That forced carry is exactly why the next place is worth 2: it represents the one overflow from the place below. More deeply: each place added to a binary number doubles the count of patterns you can form. One bit gives 2 patterns (0 and 1). Two bits give 4 patterns (00, 01, 10, 11). Three bits give 8. Every extra bit multiplies by 2, so every extra place is worth exactly twice the one before it.

3

Reading binary: multiply each 1 by its place weight and sum. Given the 8-bit pattern 0 1 0 1 1 0 1 0, assign weights from right to left — 1, 2, 4, 8, 16, 32, 64, 128. Only the positions that hold a 1 contribute: add their weights and ignore positions that hold 0. The total is the decimal value of the binary number.

0
128
1
64
0
32
1
16
1
8
0
4
1
2
0
1
Binary 01011010: place weights shown below each bit. Highlighted bits (value 1) contribute 64 + 16 + 8 + 2 = 90.
4

Writing binary: convert decimal to binary by repeated halving. To find which bits are on for a given decimal number, divide it by 2 repeatedly and record each remainder. The remainders, read from last to first, spell out the binary number. This works because dividing by 2 peels off the least significant bit as the remainder: odd numbers have a 1 in the ones place (remainder 1 when divided by 2), even numbers have a 0 (remainder 0). Each division shifts the value right by one bit place, so repeating the process extracts every bit from least significant to most significant.

Why this works

Why do remainders come out in reverse order? The first division gives you the weight-1 bit (the rightmost), because that bit determines whether the number is odd or even. The second division gives you the weight-2 bit, and so on. Since we collect them starting from the least significant bit, we have to reverse the list at the end to get the normal left-to-right binary representation.

Worked example

Converting 13 to binary and back.

Decimal → binary (repeated halving):

DivisionQuotientRemainder
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Remainders from bottom to top: 1, 1, 0, 1 → binary 1101.

Binary → decimal (place value sum):

1101 — assign weights right to left: 1, 2, 4, 8.

BitWeightContribution
111
020
144
188

Sum: 8 + 4 + 0 + 1 = 13. We are back where we started.

Common mistake

A common error is reading binary left to right without assigning place weights first. The leftmost bit does not have weight 1 — it has the highest weight in the pattern. In an 8-bit number the leftmost bit has weight 128. Always anchor the weight-1 position at the right end, then double leftward: 1, 2, 4, 8, 16, 32, 64, 128.

Practice 0 / 5

What is the decimal value of the 4-bit binary number 1010? (Place weights: 8, 4, 2, 1.) Type the number.

What is the decimal value of the binary number 1111 (4 bits)? Type the number.

Convert decimal 6 to a 4-bit binary number. Type the decimal equivalent of the result to verify: what decimal does 0110 equal?

How many distinct values can a 4-bit binary number represent? (Count from 0000 to 1111 inclusive.) Type the count.

What is the decimal value of the binary number 10000000 (8 bits)? Type the number.

Check yourself
Quiz

Why does adding one more bit to a binary pattern exactly double the number of values that pattern can represent?

Recap

Binary numbers use place value exactly like decimal, but with powers of 2 instead of powers of 10. The rightmost bit has weight 1, the next has weight 2, then 4, 8, 16 — each place is twice the one to its right. To read binary, sum the weights of every position that holds a 1. To write binary, divide the decimal number by 2 repeatedly and read the remainders from last to first. Adding one bit doubles the count of representable values because every existing pattern gains a twin with the new bit set to 1.

Continue the climb ↑Encoding the world
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.