Computers do their numbering
and do math a little bit differently than we do.
Now, as a kid, you learned
to count in what's known as base 10.
This is a decimal number, right? Decimal meaning 10.
And so when I count, you would start at zero
and you go 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Now, what comes next?
Well, we go to the second column,
we put a one there and we go back to zero.
So now we go from nine to 10, and then we keep counting up
and eventually, we get to 98, 99,
and then we go, ah, I need another column.
Put another one there and add two zeros. That's 100.
So go 98, 99, 100, right?
And that's the whole idea here
when we talk about decimal, right?
When we talk about decimal,
we only have 10 choices for the numbers.
Each decimal place can only be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Those are our 10 options.
Now, computers and networks
don't actually understand decimal natively.
So even though we've been using decimal when talking
about IPv4 addresses, that's not how computers see them.
Computers do everything in binary,
which is base two numbering.
That means every single digit
is either a one or it's a zero.
That's an on or it's an off.
That is how computers understand things.
And so when they count, they go,
0, 1, 10, 11, 100, 111.
And they keep going like that.
The 10 is actually the number two for us,
but for them in binary, that is actually a 10.
And 10 equates to two
because it's the third thing we got to.
0, 1, 2.
Now, that's the way this works with a computer.
And so we have to understand
how things are written in decimal
and how things are written in binary
and how to convert between the two.
And that's what we're going to talk about
in this particular lesson.
Now, when we convert from binary to decimal,
we're going to do this using a table
that I have here on the screen.
Each number is a factor of two.
And so this way, we can start going
and putting them as placeholders of one or zero
as we go through each place.
So if we start on the right and we go left, we have one,
and then we have a place of one, right?
Now, if I put a one, zero in the second
and first columns, this is going to become two.
And we keep going through as we keep counting.
Now, if you're not getting it quite yet,
you will by the end of this lesson, I promise.
So let's just keep going ahead
and we're going to do some examples together.
Let's say I give you the binary number of 10010110
and I asked you to tell me what is this
if I put it into decimal?
Well, we're going to first by populating the table,
starting from the right and going to the left.
And so we're going to put the number there
that we have from right to left
and end up with what you see here on the screen.
It turns into 1001011 and 0.
Now, there's a place where there's a one,
and I'm going to add the number above it.
So if I see something like 128 plus 16 plus 4 plus 2,
and I add that all together, I'm going to get 150.
That is the number 10010110 in binary,
and it translates to 150 in decimal.
You see how easy that is if you have the little chart?
So if you make this chart on your paper when you sit down
for the exam, it's going to make things a lot easier for you.
Again, going from right to left on the chart,
each position starts out with the number
of 1, 2, 4, 8, 16, 32, 64, 128.
We keep multiplying by two as we go from right to left.
And so if I added up every single one of those
with a one in it,
guess what the biggest number I could get is.
255, which if you remember when I talked about IPv4,
all my numbers were either zero all the way up through 255.
That's my four octets.
Well, that's because I have eight digits in each
of those octets, right?
And each digit, each binary digit
can only hold a one or a zero.
Now, what if I gave you a decimal number,
like from an IP address
and asked you to convert that to binary?
Could you do it? Well, the answer is yes.
It's the exact same process we just did.
So let's take a number from 167
and convert it backwards to binary.
That'd be one of the octets inside
of an IP address, for instance.
Well, instead of adding up, we're going to be subtracting.
So when I do this, I'll take 167
and I'll start from the left.
Can I take 128 out of 167? Yes, I can.
And I'll have 39 leftover. Then I go to the next column.
That's 64. Can I take 64 from 39?
No, because there's not enough there.
So I'll put a zero under the 64 column.
Then I'll say, can I take 32 out of 39?
Yes, I can, and I'll have seven leftover.
So I'll put one in that column.
Then I look, can I take 16 from seven? No, so I put a zero.
How about eight from seven? No, so I put a zero.
How about four from seven?
Yes, and that leads me with three.
Can I go ahead and take two from three?
Yes, I'll put a one in that column.
And then can I take one from one?
Yes, and I'll put a one down for that.
And this is how you convert from decimal back to binary.
You're going to subtract on the way down.
Just like what I went from binary to decimal,
I added up, going from decimal to binary,
I'm going to go ahead and subtract.
Now, either way, if you have this chart down, these factors
of two, it makes these problems very, very easy.
So now that we have that example under way
and we see that 167 is actually 10100111,
how can I check my math and make sure I got it right?
Well, I can go the other direction
and I can add up the numbers,
and if they all come back to 167,
that means I did the problem correctly.
So let's check our answer.
128 plus 32 plus 4 plus 2 plus 1.
That equals 167.
That means we did our math problem correctly.