Counting in binary
Counting with only two digits, and reading a binary number without thinking.
Counting with two digits
You already count in a system with a limited set of digits: ten of them, 0 to 9. When you run out, you write a 0 and carry a 1 into the next column to the left, which is how 9 becomes 10. Binary is the very same idea with only two digits, 0 and 1. You run out much sooner, so you carry much more often, but the rule is the one you already know.
Count up from zero and watch when the carry happens:
0, 1, 10, 11, 100, 101, 110, 111, 1000, …
After 1 you have run out of digits, so you write 0 and carry: 10. That is two. Then 11 is three. Then both columns are full, so both carry: 100 is four.
Common mistake: reading 10 as ten
In binary, 10 is two, not ten. It helps to read binary numbers digit by digit, "one zero", rather than "ten", until the habit is broken. When it matters which system a number is in, people write a small 2 or 10 after it: 102 is two, 1010 is ten.
Place value: every bit has a weight
In decimal, the columns are worth 1, 10, 100, 1000: each column is ten times the one to its right. In binary each column is twice the one to its right, so the columns are worth 1, 2, 4, 8, 16, 32 and so on. Those column values are called weights. A binary number is read by adding up the weights of the columns that hold a 1 and ignoring the columns that hold a 0.
Worked example. What is 1011 in decimal?
Write the weights over the bits, from the right: 8, 4, 2, 1. The bits that are 1 sit under 8, 2 and 1. Add those: 8 + 2 + 1 = 11. The 4 column holds a 0, so it contributes nothing.
Going the other way: decimal to binary
To write a decimal number in binary, walk through the weights from the biggest down and ask of each one, "does this fit in what I have left?" If it does, write a 1 and subtract it. If not, write a 0 and move on.
Worked example. Write 13 with four bits.
Weights from the left: 8, 4, 2, 1. Does 8 fit in 13? Yes: write 1, and 13 − 8 = 5 is left. Does 4 fit in 5? Yes: write 1, 1 is left. Does 2 fit in 1? No: write 0. Does 1 fit in 1? Yes: write 1, nothing left. Reading the digits in order gives 1101.
Check it by going back: 8 + 4 + 1 = 13. Going both ways and checking that they agree is a habit worth keeping for the whole course. It catches most slips.
Why the width matters
A real circuit has a fixed number of wires, so it holds a fixed number of bits. That number is the width, and it decides the biggest number the circuit can hold. With four bits the biggest pattern is 1111, which is 8 + 4 + 2 + 1 = 15. With eight bits it is 255, and in general with n bits it is 2n − 1: one less than the number of patterns, because one of the patterns is spent on zero.
Try counting past the top of the four-bit strip above: 1111 plus one would need a fifth column, and there is not one. In a real circuit the carry falls off the end and the number wraps round to 0000. Later in the course, when you build an adder, you will see that carry come out on its own wire.
Why?: why not just use more bits?
More bits means more wires, more gates and more power for every single operation, so designers choose the smallest width that fits the job. A traffic light controller might use three bits; a video game console uses sixty-four. Leading zeros are free, though: 5 in eight bits is simply 00000101.
What to remember
- Binary counts with 0 and 1 and carries into the next column whenever a column is full.
- Each column has a weight, doubling from 1 on the right: 1, 2, 4, 8, 16, 32.
- To read a binary number, add the weights of the columns holding a 1.
- To write one, go through the weights from the biggest down and take each one that fits.
- A circuit's width is its number of bits, and the biggest number it can hold is 2n − 1.
Check yourself
Get 5 right in a row and the lesson is done. A wrong answer costs the run, not the lesson.
What is 0001 in decimal?
0001
Already know this? and come back to the quiz any time.