Powered by Innings 2

Glossary

Select one of the keywords on the left…

6th class > > Binary Numbers

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. Transistors are the building blocks of how computers store and manipulate information.

transistor_on

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 .

1
2
3
4
5

A drawback of this strategy is that there are many unused finger combinations. For example, this finger combination to the right would represent . With our traditional model there are two fingers up, so it means two. But we already have a configuration for two! We're wasting valuable space.

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 binary numbers. Instead of using the number of fingers up as our count, we have to do something a bit more complicated.

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.

0
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 . possible combinations. Remember that our fingers are merely serving as a metaphor for binary numbers. This means that any n-digit number can represent up to 2^n different values.

1s and 0s

Recalling our lesson on probability trees, with each finger that we add our number of options multiplies by two.

01010101010101010101010101010101010101010101010101010101010101

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 different combinations we can make with five fingers.

Decimal
Binary
0
00000
1
00001
2
00010
3
00011
4
00100
5
00101
6
00110
7
00111
8
01000
9
01001
10
01010
11
01011
12
01100
13
01101
14
01110
15
01111
16
10000
17
10001
18
10010
19
10011
20
10100
21
10101
22
10110
23
10111
24
11000
25
11001
26
11010
27
11011
28
11100
29
11101
30
11110
31
11111

(we'll find out soon why we started with zero). Change the tabs to toggle between the binary values and their decimal counterparts.

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 base ten number system. Base ten numbers have ten possible values for each digit. 0 1 2 3 4 5 6 7 8 and 9. In a base-ten number, each digit is worth ten times as much as the previous smaller digit. The first right-most digit represents how many there are, the second right-most digit represents how many there are, and so on.

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 .

numberhundreds valuetens valueones 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 as much as the previous digit. And because in a binary number each digit can either be 1 or 0, each digit value can be either on or off.

Let's examine the binary number 11111 (5 consecutive 1s). How much is each digit worth?

digit11111
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 = + 0 + 0 + + + 0 =

111000 = + + + 0 + 0 + 0 =

101011 = + 0 + + 0 + + =

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)

ch_full Created with Sketch. 25 1 1 0 0 1 16 8 4 2 1
We have a full block of length 25.
We always start with the leftmost digit. In this case, 16 is the largest power of 2 that can fit into 25. So first we test the 16s place.
We can subtract 16, so we write a [1 in the 16s place](->.#digit16). We're left with 9.
Next we test the 8s place.
We can subtract 8, so we write a 1 in the 8s place. We're left with 1.
Next we test the 4s place.
We cannot subtract 4, so we write a 0 in the 4s place.
Next we test the 2s place.
We cannot subtract 2, so we write a 0 in the 2s place.
Next we test the 1s place.
We can subtract 1, so we write a 1 in the 1s place. We're left with 0, and we are finished.

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:

  1. Start with the highest power of 2^n, d, that you can subtract from N.
  2. If you can subtract d from N, then write a 1 in that place and continue with N = N - d.
  3. If you cannot subtract d from N, then write a 0 in that place and continue with N = N.
  4. Divide d by 2 to get the next digits place.
  5. 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:

  1. Find the highest power of 2 that you can subtract from N, let's call it d
  2. Subtract d from N to get how much you have left. Write a 1 in the first digit. Let's call this value N'
  3. Divide d by 2 to get the next digits place. This will always be the next highetst power of 2.
  4. 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.
  5. 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.