< Day 2 Day 4 >
This post is part of a series I hope to publish regularly called "1 Times Daily." The idea is simple: that almost anyone can learn about computer science. I'm going to try to boil CS down to its core and present that in a way that nearly everyone can understand. I'll do my best to write from a "general audience" perspective, and we'll see if anyone bothers to read!
Day 3: Computers deal in yes/no responses.
Let what you say be simply ‘Yes’ or ‘No’; anything more than this comes from evil. -Jesus Christ, Matthew 5:37 (English Standard Version)
Computers deal in yes/no responses. I know what you're thinking. Just yesterday, I spent many words trying to convince you that computers deal in numbers, and now they're dealing in yes and no! The two are actually very compatible. Let's talk about light switches.
We can think of a standard light switch as a physical representation of a yes/no response. One important property of the light switch is that it's either "on" or "off". There is no middle ground or scale from one to ten - only the "on" position and the "off" position. (In CS, we refer to the current position or value of something as its "state"). Computers need this precision and, without getting too technical, the trick to modeling it on their equipment comes from electricity. If the input to a chip has a significant electrical current, its value is "yes" - otherwise, it's "no". And this is a major reason why, at the lowest level, your computer deals in yes/no responses.
Now that you're hopefully convinced that these yes/no responses are a good idea, I must convince you that they can be used to represent the almighty numbers I pitched just yesterday. To be precise about this, we have to talk about some math.
All over the world, people like to use a number system built around the number 10. In elementary school, we're usually taught an idea called "places", e.g., the ones place, the tens place, the hundreds place, etc. We're counting by 10s all of the time, and once we get 10 of something, we move to the next "place" (sometimes we call the number in each place a "digit"). When it comes to storing a number on a computer, each digit can be in one of 10 possible states: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. But computers only have "light switches," which can represent 2 states (not 10). The solution in CS is to use an alternative number system which counts by 2s instead of 10s. This number system based on 2s is called "base 2" instead of "base 10" and often referred to as "binary" (in contrast to base 10's"decimal").
Amazingly, all we lose by switching to binary is the number of states possible for each digit. We can still count as high as we want, we just need more digits! Binary gives rise to a 2s place, 4s place, 8s place, etc. (As a cool factoid, these "places" are counting by the powers of 2. 2^0 = 1, 2^1 = 2, 2^2 = 4, etc. just like 10^0 = 1, 10^1 = 10, 10^2 = 100, etc. for decimal!) Let's practice:
If we let 0 = "no" and 1 = "yes", then we've finally reduced all numbers down to a series of yes/no answers. So as it turns out, computers can prefer both numbers AND yes/no answers. Next time, we'll be looking at another important aspect of these yes/no answers (with much less math). Thanks for reading!