Binary Numbers
Computers are all around us. You’re reading this on a computer right now! But how many people actually know how computers work? How many of us, as we scroll through our social media feeds, or search for a recipe, or watch a movie from our favorite streaming service know how what's happening actually works?
There are many many complex layers and processes that operate together to get information from all over the world and display it on your screen. But at the lowest level of every computer are
Transistors are like tiny microscopic electrical switches that transmit electrons. Turn on a transistor and the electrons flow. Turn it off and the electrons stop (Perhaps this sounds familiar to the telegraph).
But how can a simple on/off switch store information as complex as sound, images, and videos? We learned in the last chapter about Morse Code, which is used to communicate letters via sound or light. But transistors store data that is interpreted by a computer through very different means.
To understand how all sorts of different codes can be stored in the transistors of a computer, let’s try a thought exercise. We've just looked at how a transistor can be turned on or off, now let's look at how we can count on our fingers by putting them up or down.
Playing with Digits
How high can you count using only one hand, without skipping any numbers? When we count with our hands, we traditionally use how many fingers are up to represent the number. We have five fingers, so that means the highest we can count with one hand is
A drawback of this strategy is that there are many unused finger combinations. For example, this finger combination to the right would represent
There is a way that we can count much higher while still using only one hand, and this counting method will also help us understand how transistors store information. The secret lies in something called
We can treat each of our fingers as a digit with one of two possible values: down or up. Down can represent the number 0 and up can represent the number 1.
If we want to use each combination of ups and downs to represent a different number, then how many combinations can we represent? (Link back to combinatorics).
Number of fingers | Possible combinations |
1 | |
2 | |
3 | |
4 | |
5 |
.head Number of fingers | .head Possible combinations. |
1 | |
2 | |
3 | |
4 | |
5 |
More generally, with n fingers we can represent
1s and 0s
Recalling our lesson on probability trees, with each finger that we add our number of options multiplies by two.
We can represent any five-digit binary number by following any path from beginning to end. For example, this is the binary sequence for 10110.
Yes, there are
(we'll find out soon why we started with zero). Change the
Transistors
Now that we have learned a bit about how we can represent different values by strings of 0s and 1s, let's tie this back to transistors. Recall how in our morse code/flashlight examples we were constrained by our medium’s ability to be on or off. Computers store data in transistors, so they store data as a collection of ons and offs, or 1s and 0s. Just like we just did with our fingers (by putting them up or down). If a computer had fingers, they would probably count to 31 on one hand. Everything that’s stored on a computer, from text and images to video and sound is stored in transistors as sequences of 1s and 0s, or binary code.
Another way we can imagine these transistors is with a series of lights.
This is how the sequence 10011011 would be stored.
Binary to Base-Ten
Before we can understand how computers use binary code to store complex things like sound and video, we must first understand the basics, like how a base-ten number is stored.
Our number system operates as a
The value represented by each digit is the digit number times the value of the digit. So A four in the hundreds place represents the value
number | hundreds value | tens value | ones value |
432 | |||
907 |
To find the value of a base ten number, we add up the values of each digit!
Binary numbers work very similarly except they use a base-two number system. So instead of ten possible digit values, they only have 2. Each consective digit is worth
Let's examine the binary number 11111 (5 consecutive 1s). How much is each digit worth?
digit | 1 | 1 | 1 | 1 | 1 |
digit value |
We can find the decimal value of this binary number 11111 by adding up the digit values. So its value is not eleven thousand, one-hundred and eleven, but is
16 + 8 + 4 + 2 + 1 =
Here are some 6-digit binary numbers. Let's convert them to decimal by first writing the values of each digit, and then adding the digits together.
100110 =
111000 =
101011 =
When computers (including digital calculators) add and subtract numbers, this is how the numbers are represented at the level of the transistor!
Converting Base-Ten to Binary
Now that we know how to convert a binary to decimal, how can we convert a decimal to a binary number? This solution is not as obvious. Follow the animation below to visualize how to break a decimal number into binary digits.
Imagine a conveyor belt that slides a large block of a gelatin-like material. This block has a length of a discrete integer. Along the conveyor belts are claws that can only fit the size of 2^N multiples. The claw will ONLY pick up a slice of its exact size, and will subtract it from the block. The block slides along until it has gone under each and every one of the claws (digits).
make this design more consistent with the rest of Mathigon. {.fixme} there is potential to make the text in the slide legends point to the diagram (see third slide)
I'm not sure exactly how to format this, Could just leave as is, or could do as a proof (see below).
Here is that simple method put into steps. When converting decimal number N into binary:
- Start with the highest power of 2^n, d, that you can subtract from N.
- If you can subtract d from N, then write a 1 in that place and continue with N = N - d.
- If you cannot subtract d from N, then write a 0 in that place and continue with N = N.
- Divide d by 2 to get the next digits place.
- Repeat steps 2 through 4 until you have written the 1s place.
I don't think "proof" is the right format, but it should look something like this. Here are the steps generalized:
- Find the highest power of 2 that you can subtract from N, let's call it d
- Subtract d from N to get how much you have left. Write a 1 in the first digit. Let's call this value N'
- Divide d by 2 to get the next digits place. This will always be the next highetst power of 2.
- If you can subtract d from N' (if N' > d), then do so and go back to Step 2. Otherwise, do not subtract and write a 0.
- Repeat steps 3 and 4 until you've done all digits.
Other places you might find binary patterns.
If you look around, you can find patterns related to binary numbers in computers, and in some other unexpected places!
When you’re looking to buy any digital device with memory like a Smartphone, Tablet, Computer, or SD Card the options often come with Memory options that are a power of 2, like 16GB, 32GB, or 64GB.
Colors on computers are stored using a combination of letters and numbers. This is another base system called hexadecimal, which is a base-16 system. Each color has a Red, a Green, and a Blue value, each of which is a number between 0 and 255.
In 2016, the messaging app WhatsApp increased the maximum number of possible users in a single group to 256 (2^8).
Many sports tournaments start with a number of teams that is a power of two. The NCAA Basketball Tournament begins with 64 (2^6) teams and has rounds called “The Sweet Sixteen”, “The Elite Eight”, and “The Final Four” (each of which is a power of two!).
The I-Ching is an ancient Chinese divination text. It contains 64 different "Hexagrams", each of which is made up of six horizontal lines which can be either solid (Yang) or divided (Yin).
Conclusion
Conclusion
Now that you've learned about binary numbers, you can make this joke to your friends:
Make this bigger and centered.
There are only 10 types of people in the world: those who understand binary, and those who don't.