This is part 1 of a 5-part series on character encodings in international data journalism. Check out the other pieces.
As you might know, computers can only talk in numbers. Specifically, binary numbers - long strings of 1
s and 0
s that somehow get converted into everything we hold dear.
If you have sound, I recommend you watch this clip from Mr. Wizard.
Binary numbers look a little something like this:
1000 1011 0100 1001 0000 0111 0001 0100 0110
(The spaces aren’t actually part of binary, they’re just in there so you can read them more easily.)
Binary numbers represent the same numbers as our normal written numbers, a.k.a. decimal numbers. For example, 42 in decimal is 101010
in binary, and 011011001
is 217. But how does it work with only 1
s and 0
s? First let’s take a look at how decimal numbers a.k.a. normal numbers work.
When we talk about each digit in a decimal number, we have names for each spot - the ones place, the tens place, the hundreds place. These names are important! Let’s think about 742
for a second.
What’s it mean when you have a 7
in the hundreds place? Our number has seven one-hundreds in it.
What’s it mean when you have a 4
in the tens place? Our number has four tens in it.
And a 2
in the ones place? Yup, two ones.
And there’s the magic! 742 just means seven one-hundreds + four tens + two ones.
Decimal number | No. of 100s | No. of 10s | No. of 1s | Represents |
---|---|---|---|---|
123 |
1 | 2 | 3 | 1 100s + 2 10s + 3 1s |
54 |
0 | 5 | 4 | 0 100s + 5 10s + 4 1s |
9 |
0 | 0 | 9 | 0 100s + 0 10s + 9 1s |
520 |
5 | 2 | 0 | 5 100s + 2 10s + 0 1s |
The number 9
is actually 009
- it has a zero in the 100s place, a zero in the 10s place, and a 9 in the 1s place. That’s zero 100s, one ten and nine ones, totaling up to 9.
It might seem obvious, but you’ll see why I’m breaking it down that way in a second.
Decimal numbers get their name from the Latin decimus, “tenth,” while binary comes from bini, meaning “by twos”
Binary starts off exactly the same as decimal does, with a ones place. But since you can only use two numbers - 0
and 1
- you can only count up to 1 before you run out of numbers!
Binary number | No. of 1s | Decimal |
---|---|---|
0 |
0 | 0 |
1 |
1 | 1 |
When we’re counting with decimals in the ones place and reach 9, we can’t go any higher without adding a new digit. This new digit represents the next-highest number, 10 (i.e. the tens place). We go from zero tens and nine ones (09
) to one ten and zero ones (10
).
It’s exactly the same with binary! Now that 1
has us at the highest number we can represent, 1, we need a way to represent the next-highest number, 2. We solve this by adding another digit to represent the number of twos.
With the number 1, we had zero twos and one one (01
). Now we have one two and zero ones, which means we’ll represent 2 as 10
in binary.
Pop quiz: what’s the binary number 11
mean in decimal?
Let’s take a look at what what numbers we can put together so far.
Binary number | No. of 2s | No. of 1s | Represents | Decimal |
---|---|---|---|---|
00 |
0 | 0 | 0 + 0 | 0 |
01 |
0 | 1 | 0 + 1 | 1 |
10 |
1 | 0 | 2 + 0 | 2 |
11 |
1 | 1 | 2 + 1 | 3 |
Now that we’re stuck at 3
, how do we get to 4
? That’s right, add a new digit that is the number of fours.
What’s going to be our next stopping point? Well, with 111
we’ll be adding one four + one 2 + one 1, giving us a maximum number of 7
.
Binary number | No. 4s | No. of 2s | No. of 1s | Represents | Decimal |
---|---|---|---|---|---|
000 |
0 | 0 | 0 | 0 + 0 + 0 | 0 |
001 |
0 | 0 | 1 | 0 + 0 + 1 | 1 |
010 |
0 | 1 | 0 | 0 + 2 + 0 | 2 |
011 |
0 | 1 | 1 | 0 + 2 + 1 | 3 |
100 |
1 | 0 | 0 | 4 + 0 + 1 | 4 |
101 |
1 | 0 | 1 | 4 + 0 + 1 | 5 |
110 |
1 | 1 | 0 | 4 + 2 + 0 | 6 |
111 |
1 | 1 | 1 | 4 + 2 + 1 | 7 |
Next digit? Yup, it’ll be the eighths place. 1000
is 8
in decimal, because it has one 8 and zero 4s, 2s and 1s.
If you noticed a pattern, you’d be right. Every new digit is twice as big as the one before it - after 8 you have 16, then 32, then 64, 128, 256, 512, and 1024!
Binary number | No. of 8s | No. of 4s | No. of 2s | No. of 1s | Represents | Decimal |
---|---|---|---|---|---|---|
0000 |
0 | 0 | 0 | 0 | 0 + 0 + 0 + 0 | 0 |
0001 |
0 | 0 | 0 | 1 | 0 + 0 + 0 + 1 | 1 |
0010 |
0 | 0 | 1 | 0 | 0 + 0 + 2 + 0 | 2 |
0011 |
0 | 0 | 1 | 1 | 0 + 0 + 2 + 1 | 3 |
0100 |
0 | 1 | 0 | 0 | 0 + 4 + 0 + 0 | 4 |
0101 |
0 | 1 | 0 | 1 | 0 + 4 + 0 + 1 | 5 |
0110 |
0 | 1 | 1 | 0 | 0 + 4 + 2 + 0 | 6 |
0111 |
0 | 1 | 1 | 1 | 0 + 4 + 2 + 1 | 7 |
1000 |
1 | 0 | 0 | 0 | 8 + 0 + 0 + 0 | 8 |
1001 |
1 | 0 | 0 | 1 | 8 + 0 + 0 + 1 | 9 |
1010 |
1 | 0 | 1 | 0 | 8 + 0 + 2 + 0 | 10 |
1011 |
1 | 0 | 1 | 1 | 8 + 0 + 2 + 1 | 11 |
1100 |
1 | 1 | 0 | 0 | 8 + 4 + 0 + 0 | 12 |
1101 |
1 | 1 | 0 | 1 | 8 + 4 + 0 + 1 | 13 |
1110 |
1 | 1 | 1 | 0 | 8 + 4 + 2 + 0 | 14 |
1111 |
1 | 1 | 1 | 1 | 8 + 4 + 2 + 1 | 15 |
So for 1010
we have (left to right) zero 1s, one 2, zero 3’s and one four. 0 + 2 + 0 + 4 = 6!
Each of of these binary digits is called a bit. A binary digit, get it? 10
is a two bit number, because it only has two avilable bits, while 0001
is a four bit number, since it has four digits.
Number of bits | Smallest Binary Number | Largest Binary Number | Decimal range |
---|---|---|---|
1 | 0 |
1 |
0-1 |
2 | 00 |
11 |
0-3 |
3 | 000 |
111 |
0-7 |
4 | 0000 |
1111 |
0-15 |
… | … | … | … |
8 | 0000 0000 |
1111 1111 |
0-255 |
As you can see, a 2-bit number can only ever count up to 3
. An 8-bit number, on the other hand, can go all the way up to 255
. The more binary digits you have available to count with, the higher you can count.
Speaking of computers: a byte is four bits, like 0000
. We won’t mention them again, but I thought you should know!
Note: When we talk about larger binary numbers, I’m going to throw in a space every four digits, so
010010
would be written as01 0010
. The space doesn’t really mean anything, it’s the same as when we use a comma for 65,536. Keeps everything tidy.
Think you’ve got it? Here’s a tiny quiz:
01 1101 0100
?1111
in decimal? What numbers did you add together?10 1001
in decimal? What numbers did you add together?13
in binary?10
types of people in the world, those who understand binary and those who don’t. LOL?Answers are below. I’ve typed out the numbers so it’s a little harder to accidentally cheat.
1101
.Head back to UTF-8, Unicode, Character Encoding, and International Data Journalism → to grab the next section!