SkillGridLearn computer science by doing

Bits: a number written with two fingers

Binary is not computer magic — it is what you get when the only two things you can say are "off" and "on".

11 min · 35 XP

You have ten fingers, so you count in tens: the digit 9 is the last one and then you start a new column. A wire has only two states — no voltage and some voltage — so a circuit counts in twos. The digit 1 is the last one, and then it starts a new column. That is the whole reason computers use base 2. It is not cleverness, it is a shortage of fingers.

In decimal, moving one place left multiplies a digit by ten: ones, tens, hundreds. In binary the same move multiplies by two instead: ones, twos, fours, eights. So the binary 1011 is one 8, no 4, one 2 and one 1 — which adds up to eleven. Same idea as the number 1011 in decimal, just with a weight of 2 per column instead of 10.

128  64  32  16   8   4   2   1
  1   0   1   1   0   0   1   0

  1*128 + 0*64 + 1*32 + 1*16 + 0*8 + 0*4 + 1*2 + 0*1
= 128 + 32 + 16 + 2
= 178Reading 10110010 as a byte, one column at a time

One wire carries one bit. Group eight wires and you have a byte: 256 possible patterns, enough for a letter, a small number or a shade of grey on a screen. Eight is not a law of nature — processors simply settled on it because the numbers worked out nicely, and now everything is built around it.

SwitchWireReceiverswitch pressed down5 voltshigh levelsamples the wire, reads a 1switch released0 voltslow levelsamples the wire, reads a 0

Practice

  1. What decimal number is the binary 1011?

    Hints
    • Write the weights 8, 4, 2, 1 above the digits and keep only the ones under a 1.
    • 1011 means one 8, no 4, one 2 and one 1 — add them up.

    12 XP

  2. Put the steps in order to see how many wires the number 13 needs and what it looks like as a byte.

    Hints
    • Count how many wires the number needs in the circuit before it can be stored.
    • Write the number in binary, then fill up whole groups of 8 bits with zeros on the left.

    11 XP

  3. Match each binary value with what it means.

    Hints
    • A byte is a fixed group of 8 wires, no matter what number sits on them.
    • Leftmost digits weigh the most, so removing them costs the most.

    12 XP