sciandu
Computer science

Computer science

Binary numbers

Just on and off: how computers represent every number in the world with 0 and 1.

What you need first

A light switch only knows on and off, and yet with five switches you can already count to 31. Every computer works exactly like that: deep inside there are only two states, current on and current off. From these two states it builds numbers, texts, photos, and entire games. Here you will see how that works with numbers.

Place values: 1, 2, 4, 8, 16

In the decimal system, the places are worth 1, 10, 100: each place is worth ten times the one to its right. In the binary system there are only the digits 0 and 1, so each place is worth twice the one to its right instead of ten times as much: 1, 2, 4, 8, 16 and so on, read from the right. A 1 means: this place value counts. A 0 means: it does not. So the binary number 101 means 4 + 0 + 1, which is 5.

Bit switches
128
64
32
16
8
4
2
1

10010110

10010110 = 128 + 16 + 4 + 2 = 150

Try it: switch individual places on and off and watch which decimal number appears.

From binary to decimal and back

Binary to decimal is pure adding: write its value under each place and add all values that have a 1. For the way back, first look for the largest place value that still fits into your number, then work down through the smaller ones. For 11 that is 8, because 16 would already be too big. Does 8 fit? Yes, write a 1, and 3 are left over. Does 4 fit? No, write a 0. Does 2 fit? Yes, another 1, and 1 is left over. Does 1 fit? Yes, one more 1. Result: 1011.

Counting with 0 and 1

Counting works in binary just like in the decimal system, except the carry comes much earlier: 0, 1, and the place is already full. It continues with 10, 11, 100, 101, 110, 111. Whenever all places show 1, the next step flips everything to 0 and a new 1 appears on the left, exactly like 99 + 1 = 100.

Exercises

0 of 6 solved

Time to try it yourself. You can't break anything, every attempt counts.

Which digits exist in the binary system?

What is the binary number 10 as a decimal number?

What is the binary number 101 as a decimal number?

Match each binary number to its decimal number.

10
100
111
1000

What is the binary number 1101 as a decimal number?

Put the binary numbers in the order you reach them when counting from 1.

  1. 1100
  2. 211
  3. 31
  4. 410
  5. 5101

Where this leads