Lecture Outline: Binary Notation

advertisement
Lecture Outline: Binary Notation
Remember, last lecture we looked at the fundamental building block of a
computer: the switch. To keep the switch simple and inexpensive, a binary switch
was selected. Of course, the switches inside a computer don’t look like this, but
you can imagine a wall light switch (with a knob to turn the lights on or off), or a
knife switch like the circuit switch you might see in a bad B-grade movie where a
convict is electrocuted (when the switch is thrown, electricity flows, when the
switch is pulled back, the circuit is broken and no electricity flows). Okay: so we
have a mental model of a switch. Let’s go back to the light switch: we want to
notate or describe a current state of the switch. If the switch is pushed to the
“ON” position, we would describe the state this way: voltage is above the
threshold. If the switch is pushed to the “OFF” position, we would describe the
state this way: voltage is below the threshold. Now, who wants to say all that?
So, people got together and agreed to this:
Voltage above the threshold = 1
Voltage below the threshold = 0
This was an amazing breakthrough. Why? Because once a numeric system was
selected to notate voltage states, we could forget for a moment that we were
describing voltage, and just focus on the numbers.
The numbers? 0 and 1, the only numbers in the base two numbering system.
Another name for base two numbering is binary.
Now, before you get cranked up, base two is a positional numbering system, just
like base ten…. And you’ve been doing base ten all your life. Believe it or not,
you know a lot about base two, you just need to map it what you know about
base 10.
Since all day long we work in base ten, no one bothers to write a little 10
subscript after an everyday number, such as this:
37210
The base ten is implied. And, believe it or not, in third grade you interpreted the
values of a number such as 37210. You said something like this:
327 = (3 * 100) + (7 * 10) + (2 * 1)
Here’s a simplification of that:
327 = (3 * 102) + (7 * 101) + (2 * 100)
The zero power is a little weird, but just remember this rule: anything raised to
the zero power, except for zero, is equal to 1.
And remember this: in base 10, numbers go from 0 – 9 until the “odometer rolls
over”.
Mapping that to base two (why base two? Cuz we have two positions of our
binary switch, on and off, which we are describing as 1 and 0), here’s what we
have:
1012 = (1 * 22) + (0*21) + (1 * 20)
Putting the number in the form above gives us an easy way to get from base two
back to base 10:
1012 = (1 * 4) + (0 * 2) + (1*1) = 4 + 0 + 1 = 510
Can you see that, by the same process (Called Expanded Notation, by the way)
11012 = (1 * 23) + (1 * 22) + (0 * 21) + (1 * 20) = 8 + 4 + 0 + 1 = 1310
How can we go the other way? In other words, start with base ten, and convert it
to base two?
There are several approaches to accomplish this. The approach illustrated in the
lecture was this:
Write out across your paper the various power values for two. How many? In our
course, through 16 is almost always enough. Write them from right to left, just as
you would write a number in base ten (the ones to the right, then the tens, then
hundreds, etc.)
Power of Two with Equivalent Value in Base Ten
= 16 23 = 8
22 = 4
21 = 2
20 = 1
24
Now, take the base ten number you want to convert, let’s say 13
Compare 13 to the leftmost number (here, 16). If 13 is equal to or greater than
16, then put a 1 under the 16. In our case, 13 is NOT equal to or less than, so we
put a 0 in that column. Make sure you read the **** notes at the bottom. Follow
along row by row::
24
= 16
Power of Two with Equivalent Value in Base Ten
23 = 8
22 = 4
21 = 2
20 = 1
Remainder
-------
Is 13 >= 16? No!
**
0
Is 13 >= 8 yes!
1
13- 8 = 5
5–4=1
Is 5 >= 4? Yes!
1
Is 1 >= 2 No!
0
Is 1 > = 1? Yes!
1
** Put a 0 in the column when an answer is NO
Put a 1 in the column when an answer is YES
**** Keep goin’ until the answer in this column is 0
Read the answer (in blue) 11012
So: 1310 = 11012
Wasn’t so hard, now was it?
1-1 = 0 ****
Here’s the most important part: SO WHAT?????
Well, we want to know how this computer-thing works. Inside, we have binary
switches. One switch, we could send 2 signals (on, off). Put two switches
together, we could say 4 things. Put 3 switches together, we could say 8 things,
etc. This idea, of stringing together switches and treating them like a little unit of
meaning is important, because it allows us to start encoding lots of things
digitally. What all do we want to encode? Numbers, pictures, sound, etc. This
lecture looked at encoding numbers. Is it possible to take our common base ten
numbers and somehow encode them using our binary switches? You betcha! If
you type the number 13 on the keyboard, magic fairies come (prove to me that
they don’t!) and use an algorithm like you learned above, and turn the base ten
number into a base two number, and then walk down a bank of switches and
throw them to meet the pattern. In the case of 13, four switches are used – and
set to the pattern of 1101. (First switch is set to 1, 2nd is set to 1, 3rd is set to 0, 4th
is set to 1 = 1101. When you need the number back, the reverse happens, and
the 1101 is decoded using expanded notation, and you see a 13!
Hope this helps you!
Download