Computers work very much like our brains. They take in information, they process that information, and then they send new data based on that processed information - or rather, give some output.
Our body has 5 (or more) senses. These senses provide input to our brains which process the information and then based on that information, they send messages to different parts of our body which causes those body parts to act on that information.
Computers take input through input devices such as a mouse, keyboard, sensors, touch screens, track balls, graphic pads, etc. They process that information with the CPU (Central Processing Unit) and then output information to output devices such as monitors, printers, robots, gaming systems, etc.
The input and output devices send and receive codes that let them know what to do. The codes were originally based on electricity. To understand this better, let's back up a little bit to understand electricity better.
Our light bulbs and many of the appliances we use that need electricity - refrigerators, stoves, televisions, fans, dvd players, etc. use electricity with alternating current.
According to wikipedia, this means that the electricity coming into our homes from the power plant has power that periodically reverses direction. This is the type of power we get when we plug something into an outlet in our homes.
Direct current never reverses direction. This is the type of electricity a flashlight battery or AA battery delivers.
These types of energy or electricity are often visualized using waveforms - which is pretty much just a graph of how much electricity is flowing from one place to another.
Alternating current makes a sine wave when graphed. Direct current makes a straight line.
Computer logic is based on the concept of direct current. Since the signal is direct and not oscillating, we can measure two states: on and off.
It's either on or off, nothing in between. Black or white, no gray area.
Early computer scientists started using 1's to indicate the on current and 0 to indicate the off current. Using currents and denoting them with 1's and 0's allowed them to send messages or signals to other devices.
In the early days, vacuum tubes were used as the digital devices to indicate 1 (on) and 0 (off). Vacuum tubes are sort of like light bulbs.
In my mind, I imagined this big machine with all kinds of light bulbs lighting up and going off at different times, much like a Christmas tree.
If each light bulb (or vacuum tube) indicates something that can be answered with a true or false, or yes or no, question, then you and I could just use a series of light bulbs to communicate.
I'm going to give you a goofy, made up example. Let's say that you and I are next door neighbors and we want to communicate with each other. We both have electricity but no phones or other communication devices. And, we are both lazy.
We could put a lamp in the window. If I turn on the lamp, that means I need you for something. If the lamp is off, that means I don't need you.
(Now, I know this is not very practical, but just bare with me.)
The lamp works well, but, let's say I wanted to communicate more than whether I needed you or not. I wanted to let you know that I needed you to go to the grocery for me OR I needed you to come watch my kids so I could go out, OR I didn't need you. I couldn't do that with one light bulb.
So, we decide to get two light bulbs. We make a secret code that if no light bulbs are on then I don't need you. If the right light bulb is on then I need you to go to the store. If the left light bulb is on, I need you to come watch my kids. I could even go so far as to turn on both light bulbs which might mean, you come over so I can go to the store.
As long as we both know the code, we can communicate.
This works so well that we start using more light bulbs to mean other things. Before long we have a whole strand of lights which are getting more and more confusing.
Finally, one of us gets the bright idea to use the binary system (based on 2 digits) of math rather than the decimal system (based on 10 digits) of math.
The binary system only uses 2 digits, 1 and 0 - on or off. It works exactly like our decimal system which uses 10 digits, 0-9. I count in decimal like this:
0 1 2 3 4 5 6 7 8 9 10 11 12...
I count in binary like this:
0 1 10 11 100 101 110 111 1000
It's easier for me to understand binary, if I think of the old odometer on my old car. They used to have little cylinders that had all 10 digits printed on them. The cylinders were lined up next to each other on a rod so I could see how many miles I had driven. As I drove, those little cylinders would turn on the rod. As the tiny cylinder on the right got to 9, the next turn of that cylinder would rollover to zero and the cylinder to it's left would rollover to it's next digit.
When we learn our numbering system (decimal) in grade school, we learn that we have the ones place to the right, the ten's place (10 x 1 = 10) to the left of that, the hundreds place (10 x 10 = 100) to the left of that, etc. Each position in a number is multiplied by 10 to get the next position's (to the left) value.
It's the same in binary, only there are only two digits. The one's place to the right. Then multiply by 2 to get the two's place just to the left of the 1's place, then multiply that by 2 to get the four's place. Each position is multiplied by 2 instead of 10 as in the decimal system.
Now, just imagine that I had 10 light bulbs in the window. We could use the base 2 system to come up with a number that would make the code easier to understand.
We could say - if the light is on it counts one point x it's place value. We use base 2 because there are only 2 options - on and off. We do not have 10 options, so if we used base 10, many of the numbers in that numbering system would mean nothing.
In our previous example, if I looked at the light bulbs and noted in my notebook a 0 if the light bulb was off and a 1 if the lightbulb was on, I could have:
00 - (zero) both off, I don't need you
01 - (one) right one on, I need you to go to the store
10 - (two) left one on, I need you to watch the kids
11 - (three) both on, I need you to watch the kids so I can go to the store.
This may be a silly example, but it helped me to understand how the ones and zeros can be combined to give instructions or tell the computer what to do.
Using electronic logic circuits and truth tables, we can combine those ones and zeros to mean different things in a computer chip or microprocessor. I'll talk about that in the next post.