NATE HARDISON: Back when you learned how to read and write
numbers, you learned about the digits 0 to 9.
To write whole numbers larger than 9, you learned that all
you had to do was use some combination of these digits,
as in 52 and 437.
So this way of writing numbers has a name, decimal notation.
>> Why decimal?
Well, the Latin root of decimal, "decem," means 10.
And when you have 10 digits in your notation system, 10
becomes a rather special number.
Let's look at the number 437 written in decimal notation to
understand why.
We can first break up 437 into 400 plus 30 plus 7.
>> We can take it apart even more so that we've got 4 times 100
plus 3 times 10 plus 7 times 1.
Remember learning about the ones place, the tens place,
the hundreds place, and so on?
This is exactly where that comes from.
And finally, we can see how we've got a bunch of powers of
10 embedded in here.
We've got 4 times 10 to the 2 plus 3 times 10 to the 1 plus
7 times 10 to the 0.
So now you see why 10 is a special
number in decimal notation.
In fact, we've got a name for it, it's called the base since
it's the base of the exponent in our arithmetic here.
>> Decimal notation is not the only way to represent numbers.
In fact, even if we get rid of the digits 2 through 9, we can
still represent all of the numbers that
we could with decimal.
So now that we have two digits, 0 and 1, 2 is our
special number, the base of our notation system.
The name of this notation system is called binary, since
the prefix "bi" means two.
So instead now of having a ones place and tens place and
so on, we now have a ones place, a twos place, a fours
place, and so on, going up by powers of two.
So let's see this by doing some counting.
So 0 still 0, and 1 is still 1.
>> However, now that we've got a twos place instead of a tens
place, 10 represents the number 2.
To get 3, we add 1 to that and get 11.
4, since there's now a fours place, is represented by 100.
Five is 101.
6 is 110.
7 is 111.
8, again, has its own place, so it's 1000.
And I think you get the point.
Let's take a stab at reading a large binary number and
turning it back into decimal notation, since that's what
we're used to.
This number, in binary, reads 101110011.
>> To figure out its decimal representation, let's start by
writing the places under each of the digits.
To start, we have the 2 to the zeros place on the far right,
followed by the 2 the ones place, 2 to the twos place, 2
to the three, 2 to the four, 2 to the five, 2 to the six, 2
to the seven, and finally, all the way up to 2 to the eight.
Now if we do the math, that's the ones place, the twos
place, the fours place, the eights place, the 16ths place,
the 32nds place, 64ths place, 128ths place, and finally the
256ths place.
Whew.
So now, if we start multiplying everything
together, we see we have 1 times 256 plus 1 times 64 plus
1 times 32 plus 1 times 16 plus 1 times 2 and 1 times 1.
>> So if we sum all of that together, we get to 256 plus
64 plus 32 plus 16 plus 2 plus 1, all for a
grand total of 371.
Translating from decimal notation to binary notation is
somewhat tricky, since we need to go from a number that's
based on powers of 10 to one that's based on powers of 2.
Let's give it go.
Here we have the number 237 in decimal notation.
To translate into binary notation, I start by finding
the largest power of 2 that's less than it, which is 128.
I put a 1 in the one hundred twenty-eighths place down here
in my binary number.
And then I subtract 128 from 237, and I get 109.
Then I just repeat the process.
The largest power of 2 that's smaller than 109 is 64, so I
put a 1 in the 64ths place and subtract 64
from 109 to get 45.
Again, the largest power of 2 that's less than 45 is 32, so
put a 1 in the appropriate slot and subtract 32--
I'm going to move up here--
to get 13.
>> Moving on, I get 8 as the largest power
of 2 now, not 16.
So I put a 0 in the 16s place, a 1 in the 8s place,
subtract, and get 5.
Then 4 is the largest power of 2.
I subtract and get 1.
Now I can finish off the translation easily.
I put a 0 in the twos place, and put a 1 in the ones place.
The result, 11101101.
>> One thing you might not have expected is that all of the
algorithms you learned to add, subtract, multiply, and divide
in decimal notation work in binary notation as well.
We'll do an example of addition.
Here we've got 1101101 plus 1010110.
Just as in decimal addition, we'll start from the right and
work our way to the left.
The only difference is that we carry a 1 if the two digits
we're adding have a sum greater than 1, instead of a
sum greater than 9, as in decimal.
So on the right, we have 1 plus 0, 1.
>> Moving to the left, we have 0 plus 1, again 1.
Moving left again, we have 1 plus 1, we write a 0,
and we carry a 1.
Then we have 1, 1, 0, so we have a 0, carry a 1.
Then 1, 0, 1, again 0, carry a 1.
1, 1, 0, 0 again, carry a final 1.
>> And finally, 1, 1, 1, so we have a 1 and a
final 1 on the left.
The result, 11000011.
And that concludes our quick
introduction to binary notation.
>> My name is Nate Hardison, and this is CS 50.