WEBVTT

00:01.360 --> 00:02.949
Hello, this is Dr. Miller, and this

00:02.950 --> 00:04.269
is Episode one point four of

00:04.270 --> 00:05.270
assembly,

00:06.160 --> 00:07.419
so today we're going to learn about

00:07.420 --> 00:08.547
binary twos, complement

00:09.340 --> 00:10.390
and hexadecimal

00:11.500 --> 00:12.500
binary.

00:13.150 --> 00:14.767
So binary is what a computer uses

00:15.310 --> 00:16.584
in order to store numbers,

00:17.260 --> 00:18.879
and it uses ones and zeros.

00:19.570 --> 00:21.429
And each bit represents a

00:21.430 --> 00:22.969
power as a power of two.

00:23.020 --> 00:24.489
So we have to do the zero two to the

00:24.490 --> 00:26.409
one, two to the two and so on and so

00:26.410 --> 00:27.759
forth until we get to two to the

00:27.760 --> 00:28.760
seven.

00:29.920 --> 00:31.749
So two to the zero represents the

00:31.750 --> 00:33.399
number one, and then we basically

00:33.400 --> 00:35.066
double as we go down the line one,

00:35.200 --> 00:37.119
two, four, eight, 16,

00:37.120 --> 00:39.189
32, 64 and one hundred and twenty

00:39.190 --> 00:40.149
eight.

00:40.150 --> 00:41.229
And when we're converting, we

00:41.230 --> 00:42.699
basically add up all these numbers

00:42.700 --> 00:44.500
in order to get our decimal number.

00:45.430 --> 00:46.629
So, for example, if we have the

00:46.630 --> 00:48.309
number thirty three, we're going to

00:48.310 --> 00:49.535
go on down the line until

00:50.200 --> 00:51.789
we get to a number that is smaller

00:51.790 --> 00:52.929
than the current number that we

00:52.930 --> 00:54.319
have. So we have thirty three.

00:54.910 --> 00:56.169
Well I don't need a hundred twenty

00:56.170 --> 00:57.789
eight. I don't need sixty four but I

00:57.790 --> 00:59.679
do need a thirty two and then

00:59.680 --> 01:00.909
we go ahead and subtract the two.

01:00.940 --> 01:02.829
So thirty three minus 32 gives me

01:02.830 --> 01:04.300
one and I can kind of shortcut

01:04.750 --> 01:06.609
and go down here to one to say I do

01:06.610 --> 01:07.610
also need a one.

01:08.080 --> 01:09.459
And so the number thirty three would

01:09.460 --> 01:10.989
be zero zero one

01:11.290 --> 01:13.239
zero zero zero zero

01:13.240 --> 01:14.240
one.

01:14.760 --> 01:15.936
That would be its binary

01:16.590 --> 01:17.590
representation

01:18.540 --> 01:19.859
to convert from decimal.

01:20.100 --> 01:21.668
We take our binary number, we go

01:21.870 --> 01:23.634
ahead and write it down, and then we

01:23.640 --> 01:24.929
just write above it all of the

01:24.930 --> 01:26.351
powers of two and everywhere.

01:27.060 --> 01:28.799
I have a one that means I want to

01:28.800 --> 01:29.800
include that.

01:29.940 --> 01:31.769
And so I need one hundred and twenty

01:31.770 --> 01:33.044
eight plus thirty two plus

01:33.780 --> 01:35.160
four plus one.

01:35.700 --> 01:37.289
By add all those together I get one

01:37.290 --> 01:38.339
hundred and sixty five.

01:38.340 --> 01:39.614
So the number one zero one

01:40.230 --> 01:42.209
zero zero one zero

01:42.210 --> 01:43.582
one is one hundred and sixty

01:44.100 --> 01:45.239
five in decimal.

01:46.960 --> 01:48.819
To compliment, so

01:48.820 --> 01:50.709
to compliment is what computers

01:50.710 --> 01:52.809
use in order to store both positive

01:52.810 --> 01:54.182
and negative numbers and the

01:54.730 --> 01:56.249
top bit or most significant bit

01:56.890 --> 01:58.069
represents the sign.

01:58.510 --> 02:00.459
So if we see a zero, that means that

02:00.460 --> 02:01.780
this is a positive number.

02:02.050 --> 02:03.879
If we see a one, that means that

02:03.880 --> 02:05.170
this is a negative number.

02:07.190 --> 02:08.299
So if we're going to convert from

02:08.300 --> 02:09.918
decimal into twos, complement,

02:10.250 --> 02:11.671
if the number is positive, we

02:12.110 --> 02:13.727
just convert it from decimal into

02:14.150 --> 02:15.529
binary like we did before.

02:16.190 --> 02:17.719
If it's negative, we're going to

02:17.720 --> 02:19.460
convert our number to binary

02:19.790 --> 02:20.929
and then we're going to flip all the

02:20.930 --> 02:22.302
bits so every zero becomes a

02:22.790 --> 02:24.740
one and every one becomes a zero.

02:25.340 --> 02:26.779
And then we'll go ahead and add one

02:26.780 --> 02:28.495
to that. And that is the process to

02:28.580 --> 02:29.780
convert from decimal to to

02:29.870 --> 02:30.870
complement.

02:33.850 --> 02:35.379
To convert from two compliment to

02:35.380 --> 02:37.449
decimal, so we have a binary

02:37.450 --> 02:38.949
number, if the most significant bit

02:38.950 --> 02:40.224
is a zero, we just convert

02:40.870 --> 02:42.369
it to decimal. So it's a positive

02:42.370 --> 02:43.929
number. We just go ahead and convert

02:43.930 --> 02:44.930
it like we did before.

02:45.550 --> 02:47.229
But if the most significant bit is a

02:47.230 --> 02:48.699
one, we're going to convert it to

02:48.700 --> 02:49.700
binary.

02:49.960 --> 02:51.577
Then we'll flip all the bits ever

02:51.610 --> 02:53.199
again. Every zero becomes a one,

02:53.200 --> 02:54.572
everyone becomes a zero, and

02:55.090 --> 02:56.139
then we're going to add one

02:57.070 --> 02:58.089
and then we'll convert it to

02:58.090 --> 02:59.349
decimal. But we've got to make sure

02:59.350 --> 03:00.526
at the end that we add a

03:01.210 --> 03:02.619
negative sign to say that this

03:02.620 --> 03:04.090
number is a negative number.

03:06.880 --> 03:08.399
So here are some binary edition

03:08.800 --> 03:10.759
facts, so we got zero point

03:10.810 --> 03:12.639
zero, we get zero and I added

03:12.640 --> 03:13.816
a leading zero here, one

03:14.680 --> 03:16.539
plus zero is one zero

03:16.540 --> 03:17.716
plus one is one one plus

03:18.580 --> 03:19.580
one is two.

03:20.050 --> 03:22.029
But we're writing in and binary.

03:22.030 --> 03:23.860
So we got a zero

03:24.760 --> 03:26.560
ones and we got one too.

03:26.590 --> 03:28.449
So we got ten and then

03:28.450 --> 03:29.626
one plus one plus one is

03:30.400 --> 03:31.400
eleven.

03:31.690 --> 03:33.429
I mean that you can go and tell your

03:33.430 --> 03:35.109
kindergartner that one plus one plus

03:35.110 --> 03:37.090
one is 11 and see what they think.

03:39.020 --> 03:40.219
So, for example, if I have the

03:40.220 --> 03:42.520
number and negative 42,

03:42.980 --> 03:44.449
well, it's negative, so I'm going to

03:44.450 --> 03:45.909
go ahead and number forty two to

03:45.920 --> 03:46.920
binary. So I need

03:47.870 --> 03:49.789
a thirty two and an eight

03:49.790 --> 03:50.719
and a two.

03:50.720 --> 03:52.460
So that gets me in my binary number.

03:52.940 --> 03:54.529
And then we flip all the bits so you

03:54.530 --> 03:56.029
can see that every zero becomes a

03:56.030 --> 03:57.800
one and every one becomes a zero

03:58.430 --> 03:59.998
and then we add one clear to the

04:00.020 --> 04:00.889
end. Right.

04:00.890 --> 04:02.017
So if I have this I say

04:02.900 --> 04:04.849
plus one, so one plus

04:04.850 --> 04:06.169
one gives me

04:06.680 --> 04:08.248
one zero and all the rest of the

04:08.360 --> 04:09.530
bits remain the same

04:10.280 --> 04:11.059
and so negative.

04:11.060 --> 04:13.129
Forty two in twos complement

04:13.130 --> 04:14.309
is this number right here.

04:14.330 --> 04:15.919
So one one zero

04:16.160 --> 04:18.410
one zero one one zero.

04:22.630 --> 04:24.100
Hex or hexadecimal,

04:24.700 --> 04:26.980
so hexadecimal is base 16

04:27.430 --> 04:28.851
and it allows us to represent

04:29.620 --> 04:31.420
binary numbers using

04:31.780 --> 04:33.639
the letters zero through

04:33.640 --> 04:35.240
nine and A through F.

04:36.220 --> 04:37.592
And so we can see the binary

04:38.410 --> 04:39.929
representation and then the hex

04:40.060 --> 04:41.049
number.

04:41.050 --> 04:42.429
So again, this is just converting

04:42.430 --> 04:44.380
from binary to decimal will give us

04:44.530 --> 04:46.049
all zeros, will give us zero or

04:46.390 --> 04:47.550
for example, six.

04:48.130 --> 04:50.709
So I got a one two four

04:50.740 --> 04:51.729
eight.

04:51.730 --> 04:53.559
So I got two plus four will give

04:53.560 --> 04:55.269
me six within.

04:55.270 --> 04:56.740
For example, we got the number

04:57.100 --> 04:58.178
ten so that's ten, ten

04:59.320 --> 05:00.759
or an eight and a two.

05:01.180 --> 05:02.680
And that gives us the letter A.

05:03.760 --> 05:05.649
All the way through F, right, so one

05:05.650 --> 05:07.689
plus two plus four plus eight

05:08.260 --> 05:09.429
will give us 15.

05:10.660 --> 05:12.339
And so one bite is going to go ahead

05:12.340 --> 05:14.620
and be too hexadecimal digits.

05:16.230 --> 05:17.729
So, again, we have the process of

05:17.730 --> 05:19.319
taking the number 42 two, and we

05:19.320 --> 05:20.819
already did the first part of the

05:20.820 --> 05:22.979
process, so I converted

05:22.980 --> 05:24.839
that into a complement

05:24.840 --> 05:26.000
and I got this number.

05:26.340 --> 05:28.139
So this number down here.

05:29.250 --> 05:30.719
And I put a space in here so that we

05:30.720 --> 05:32.339
could see the hex digits

05:32.340 --> 05:33.467
relationship, so you'll

05:34.230 --> 05:35.609
go ahead and if you're converting

05:35.610 --> 05:36.990
that into from

05:37.860 --> 05:39.239
the number negative forty two

05:39.240 --> 05:41.639
decimal to 2s complement

05:41.640 --> 05:43.499
using hex, we go ahead

05:43.500 --> 05:44.969
and do the whole process to convert

05:44.970 --> 05:46.439
to, to complement and then we got to

05:46.440 --> 05:47.440
convert to Hex.

05:47.920 --> 05:49.635
So I'll take my number one one zero

05:50.100 --> 05:51.809
one, go ahead and look it up in my

05:51.810 --> 05:53.574
table and it looks like one one zero

05:53.700 --> 05:55.589
one is a D and

05:55.590 --> 05:57.305
then I look up my other number zero

05:57.420 --> 05:58.709
one one zero.

05:59.690 --> 06:01.519
I believe that is a six

06:01.530 --> 06:02.951
and so the hex representation

06:03.440 --> 06:05.389
is zero X,

06:05.450 --> 06:07.399
so this is a prefix we generally use

06:07.400 --> 06:08.839
for hexadecimal numbers

06:09.320 --> 06:11.330
and then D six.

06:12.620 --> 06:14.120
So that represents the No

06:14.540 --> 06:15.859
negative 40 to.

06:19.830 --> 06:21.496
So now, if I'm given the number is

06:21.600 --> 06:23.420
zero X A and I

06:23.430 --> 06:25.050
want to convert that from

06:25.470 --> 06:26.695
hexadecimal to compliment

06:27.330 --> 06:29.880
into binary

06:29.910 --> 06:31.109
or our decimal.

06:31.620 --> 06:33.179
So we take the number eight and we

06:33.180 --> 06:35.129
convert that from zero from

06:35.130 --> 06:36.820
hexadecimal into binary.

06:37.440 --> 06:39.869
So A as one zero one zero,

06:39.900 --> 06:41.009
I'm going to have another one one

06:41.010 --> 06:42.259
zero one zero.

06:43.140 --> 06:45.029
Then I flip all the bits so every

06:45.030 --> 06:46.696
zero becomes one, everyone becomes

06:46.860 --> 06:47.849
a zero.

06:47.850 --> 06:49.859
I go ahead and add one again.

06:49.860 --> 06:51.079
One plus one is ten.

06:51.090 --> 06:52.199
So I have my carry.

06:53.750 --> 06:55.159
And then I go ahead and I convert

06:55.160 --> 06:56.899
this into binary, so

06:57.170 --> 06:58.787
it looks like I have a sixty four

06:59.000 --> 07:01.339
plus a sixteen plus a four

07:01.340 --> 07:02.340
plus a two, so I

07:03.200 --> 07:04.729
add those all together that gives me

07:04.730 --> 07:05.539
eighty six.

07:05.540 --> 07:07.009
And we remember that we started off

07:07.010 --> 07:08.659
with a one. Right, that told us that

07:08.660 --> 07:09.770
we needed to convert it.

07:10.400 --> 07:11.809
And so that means that this number

07:11.810 --> 07:12.919
is negative.

07:12.920 --> 07:13.920
Eighty six

07:14.840 --> 07:16.850
in decimal form.

07:19.250 --> 07:20.769
So in summary, today, we talked

07:20.870 --> 07:22.291
about binary twos, complement

07:23.540 --> 07:24.765
and then hexadecimal as a

07:25.340 --> 07:26.340
representation.

07:27.780 --> 07:29.219
Looking forward, we were going to

07:29.220 --> 07:30.959
talk about instructions and then

07:30.970 --> 07:32.490
logical operators.

07:33.720 --> 07:35.009
If you have questions, you can

07:35.010 --> 07:36.333
contact me at Miller, MJ at

07:36.870 --> 07:38.879
Unclutter Aidoo and you can find

07:38.880 --> 07:40.919
me at Twitter @

07:40.920 --> 07:42.120
@ Milhouse 30.

