What is Binary Code?

Binary code.png

Have you ever been is a situation where you asked your mother for something to eat right before dinner?  Let’s say you asked, “Mom, can I have a peanut butter and jelly sandwich?”  It’s 35 minutes before your family is about to eat and you know that the answer is either going to be “Yes.” or  “No.”, but you figure it’s worth a shot.

Think of a binary system like your mother giving you this answer right before dinner—there are only two possibilities—a yes or a no.  A binary numerical system is a base 2 system—meaning it only has two digits in its system (two possibilities represented by a 0 or a 1).  When you go higher in place value, in a binary system, you double the value every time.   

We use a decimal system—base 10 system.  We have 10 digits that represent all of the number that we express, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.  

When you go up in place value in a decimal system you are multiplying by ten each time.

The number 111 represents one 1, one 10 and one 100.

Well, in a binary system you use ONLY 0 and 1 to express numbers.

128   64   32   16   8   4   2   1  

  0      0      0   0    0   0   0   0

The zeroes you see on the bottom represent the binary numbers. The decimal numbers you see on the top translate into the numbers we typically use.  So, the numbers start from right to left and they double with each place value.

If I wanted to represent the number 128:

128   64   32   16   8   4   2   1  

  1      0      0     0    0   0   0   0
If I wanted to represent the number 64:

128   64   32   16   8   4   2   1  

  0      1      0     0    0   0   0   0

If I wanted to represent the number 32:

128   64   32   16   8   4   2   1  

  0      0      1     0    0   0   0   0

And so on…

0      0      0     0    0   0   0   0 = 0

0      0      0     0    0   0   0   1  = 1

The values, for each place value, are either turned on or off.  They are represented by number 1, if they are turned on.  They are represented by the number 0, if they are turned off, so to speak.   

Well, if we applied this to computers, “What is being turned ‘on’ of ‘off’?”    Ans: Electrical current over a wire.

Imagine a set of wires, group into a set of  eight, each with different “on” or “off” flows of electrical current.  The combination of ons and offs would combine to produce a series of 0s and 1s, which could then be used to represent other data.

We don’t have to group these wires (or “ons” and “offs”) in a group of 8, but it is a customary unit in terms of computer science application.  

So, for instance:

One digit (i.e., a 0 or a 1) is called a bit.

If you put 8 bits together, like we did in the examples above, you get a byte:

8 bits = 1 byte

A byte is a common way of grouping bits, so that when you take the entire number of possible numbers you can express (if you add 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1) 255 is the highest decimal number you can express in a byte.

If I wanted to represent the number 255:

128   64   32   16   8   4   2   1  

   1      1       1     1     1    1   1    1  =  255

Remember that the number 0 is something that also must be accounted for, so there are actually 256 different values that can be expressed, with 0 included.

And that’s exactly the concept of what a computer does, it takes a series of 0s and 1s and group them together to represent various values (even letters, symbols, etc.).

Thus, 256 values can be expressed in an 8-bit binary system.

But you can have, of course grouping in your computer’s architecture—you can have a 32-bit system, a 64-bit system, etc.

The 8-bit binary system is a foundational way of looking at things, however.  That’s important to remember because this 256 value will come up again in several ways when you study computer science, and it’s good to know that this is where it comes from (2, raised to the 8th power). 

Also, when it comes to storage this way of looking at things is also used: 

8 bits = 1 byte 

1024 bytes = 1 Kilobyte (KB)

1,048,576 bytes = 1 Megabyte (MB)

1,073,741,824 bytes = 1 Gigabyte (GB)

1,099,511,627,776 bytes = 1 Terabyte (TB)

But, let’s flow back to the concept of 0s and 1s.  

Summary

So, computers can store information as 0s or 1s by using on and off flows of electricity and grouping those 0s and 1s into bytes that can be used to perform calculations (which result in the displaying of videos, executing programs on your computer, etc.)

These 0s and 1s can not only represent numbers, but they can be used to represent characters such as letters and literally anything a computer can do.

So, when we think about the binary system, think about on and off states of current, represented by 0s and 1s in your computer, and that your computer can use those states to everything that’s done on your computer.

Danita Smith