The Wonders of Binary

Some ones and zeroes, with spaces every four digits. 
		      Specifically: 0110 0011 0110 1001 0110 1110 0110
		      0001 0111 0010 0111 1001
The string "binary" in ASCII/UTF-8 (without a null terminator)

Why is binary important?

Long ago computers were known as "differencing engines" because they found the differences between various inputs. In these first of computers the inputs and outputs to the machine were all provided and manipulated by ingenious mechanical contraptions. They used cams and cogs and worm gears to perform mathematical operations on the inputs, and spit them out in some readable form. With the introduction of the transistor though, building mechanical contraptions for every operation became more trouble than it was worth. The transistor is a powerful tool because it allows a circuit designer to switch a circuit on and off with another circuit! Even early transistors quickly had the advantage in size over their analog mechanical brethren. So the digital computer was born.

Let's back up for a second, what does "digital" mean? It means simply something based on digits! See? "Digit" is even in the word digital. It's often used to differentiate computing devices and recording media from their "analog" counterparts. So what does analog mean? It specifies something mimics it's input naturally, with all the possible states that input could have. You can see how the old camshafts and cogs did that by watching this video:

But wait, if I have an analog computer that operates exactly on my inputs, why is a digital computer that only approximates them with numbers better? It all comes down to size. Transistors are tiny (especially today), while gears and cams are large by necessity. Remember, it's not just that they have to work, it's also that they have to work for a long time and not wear down too much! Plus it's far more complex to route numbers around a mechanical assembly. You saw that it was fairly easy to add two inputs together, but think about adding hundreds! Pretty complex, right?

Okay but what does this have to do with binary? Well the transistor is basically a switch, it's either on or off, and while detecting and creating more possible voltages on the wire is doable, the pair of digit values (0 and 1) that are possible in binary naturally fit the "on/off" state of a single transistor. If you put multiple transistors together then you can just treat them individually as binary digits! And that paves the way for you to represent any number expressible with the digits (transistors) you have available!

So without binary, computers may never have moved past their gargantuan mechanical antecedents, and you might not be able to read this right now!

For more information on the history of binary, please visit its wikipedia page or the one on transistors, or do some searching with your favorite search engine!

So how does it work?

The easiest way to explain binary is to show you! So that's what I'll do. Below, you can see the way a base two (binary) number is a lot like our base ten numbers that we use all the time.

A base ten primer

First let's look at how a "normal" number looks, and break it down. This might remind you of a class you took really early on, where you first learned about the place values for numbers! The number I'm looking at is 1,423, which happens to be the first prime number with 1, 2, 3, and 4 among its digits.

1

4

2

3

×

×

×

×

103

102

101

100

=

=

=

=

1000

+

400

+

20

+

3

=

1423

See? In order to get to a base ten number, we multiply each digit by the power of ten that corresponds to its place value. Then we add all the results up! You probably do this intuitively by now whenever you think of a number, but believe it or not you once had to learn how to do this!

The binary 'b'

Now let's look at a binary number and see how it can convey the same thing. We'll convert it to base 10 so you can see that the numbers are the same. The binary number will be the ASCII code for the character 'b' in honor of binary. ASCII is a standard way of representing characters with numbers. It says 'b' is the number 110 0010 (The separation every four digits is just for readability, kinda like the comma every three digits in decimal). Anyway, let's see if we can tell what this is in decimal by applying a similar technique to above.

1

1

0

0

0

1

0

×

×

×

×

×

×

×

26

25

24

23

22

21

20

=

=

=

=

=

=

=

64

+

32

+

0

+

0

+

0

+

2

+

0

=

98

So yeah, we need a lot more digits for a given number because now each place value is multiplied by a power of two, not ten, but it's not too bad, most modern processors deal with numbers 32, 64, or even more digits long! These numbers can get pretty big (up to 1×1019 for 64 digit positive numbers, and that's a one with 19 zeroes after it!).

Parting Words

This page is totally open source and hosted on my GitHub. Check it out if you're interested.

I hope you enjoyed this journey through the basics of binary. Happy computing!

-clangdo