Hello, this is Dr. Miller, and this
is Episode one point four of
assembly,
so today we're going to learn about
binary twos, complement
and hexadecimal
binary.
So binary is what a computer uses
in order to store numbers,
and it uses ones and zeros.
And each bit represents a
power as a power of two.
So we have to do the zero two to the
one, two to the two and so on and so
forth until we get to two to the
seven.
So two to the zero represents the
number one, and then we basically
double as we go down the line one,
two, four, eight, 16,
32, 64 and one hundred and twenty
eight.
And when we're converting, we
basically add up all these numbers
in order to get our decimal number.
So, for example, if we have the
number thirty three, we're going to
go on down the line until
we get to a number that is smaller
than the current number that we
have. So we have thirty three.
Well I don't need a hundred twenty
eight. I don't need sixty four but I
do need a thirty two and then
we go ahead and subtract the two.
So thirty three minus 32 gives me
one and I can kind of shortcut
and go down here to one to say I do
also need a one.
And so the number thirty three would
be zero zero one
zero zero zero zero
one.
That would be its binary
representation
to convert from decimal.
We take our binary number, we go
ahead and write it down, and then we
just write above it all of the
powers of two and everywhere.
I have a one that means I want to
include that.
And so I need one hundred and twenty
eight plus thirty two plus
four plus one.
By add all those together I get one
hundred and sixty five.
So the number one zero one
zero zero one zero
one is one hundred and sixty
five in decimal.
To compliment, so
to compliment is what computers
use in order to store both positive
and negative numbers and the
top bit or most significant bit
represents the sign.
So if we see a zero, that means that
this is a positive number.
If we see a one, that means that
this is a negative number.
So if we're going to convert from
decimal into twos, complement,
if the number is positive, we
just convert it from decimal into
binary like we did before.
If it's negative, we're going to
convert our number to binary
and then we're going to flip all the
bits so every zero becomes a
one and every one becomes a zero.
And then we'll go ahead and add one
to that. And that is the process to
convert from decimal to to
complement.
To convert from two compliment to
decimal, so we have a binary
number, if the most significant bit
is a zero, we just convert
it to decimal. So it's a positive
number. We just go ahead and convert
it like we did before.
But if the most significant bit is a
one, we're going to convert it to
binary.
Then we'll flip all the bits ever
again. Every zero becomes a one,
everyone becomes a zero, and
then we're going to add one
and then we'll convert it to
decimal. But we've got to make sure
at the end that we add a
negative sign to say that this
number is a negative number.
So here are some binary edition
facts, so we got zero point
zero, we get zero and I added
a leading zero here, one
plus zero is one zero
plus one is one one plus
one is two.
But we're writing in and binary.
So we got a zero
ones and we got one too.
So we got ten and then
one plus one plus one is
eleven.
I mean that you can go and tell your
kindergartner that one plus one plus
one is 11 and see what they think.
So, for example, if I have the
number and negative 42,
well, it's negative, so I'm going to
go ahead and number forty two to
binary. So I need
a thirty two and an eight
and a two.
So that gets me in my binary number.
And then we flip all the bits so you
can see that every zero becomes a
one and every one becomes a zero
and then we add one clear to the
end. Right.
So if I have this I say
plus one, so one plus
one gives me
one zero and all the rest of the
bits remain the same
and so negative.
Forty two in twos complement
is this number right here.
So one one zero
one zero one one zero.
Hex or hexadecimal,
so hexadecimal is base 16
and it allows us to represent
binary numbers using
the letters zero through
nine and A through F.
And so we can see the binary
representation and then the hex
number.
So again, this is just converting
from binary to decimal will give us
all zeros, will give us zero or
for example, six.
So I got a one two four
eight.
So I got two plus four will give
me six within.
For example, we got the number
ten so that's ten, ten
or an eight and a two.
And that gives us the letter A.
All the way through F, right, so one
plus two plus four plus eight
will give us 15.
And so one bite is going to go ahead
and be too hexadecimal digits.
So, again, we have the process of
taking the number 42 two, and we
already did the first part of the
process, so I converted
that into a complement
and I got this number.
So this number down here.
And I put a space in here so that we
could see the hex digits
relationship, so you'll
go ahead and if you're converting
that into from
the number negative forty two
decimal to 2s complement
using hex, we go ahead
and do the whole process to convert
to, to complement and then we got to
convert to Hex.
So I'll take my number one one zero
one, go ahead and look it up in my
table and it looks like one one zero
one is a D and
then I look up my other number zero
one one zero.
I believe that is a six
and so the hex representation
is zero X,
so this is a prefix we generally use
for hexadecimal numbers
and then D six.
So that represents the No
negative 40 to.
So now, if I'm given the number is
zero X A and I
want to convert that from
hexadecimal to compliment
into binary
or our decimal.
So we take the number eight and we
convert that from zero from
hexadecimal into binary.
So A as one zero one zero,
I'm going to have another one one
zero one zero.
Then I flip all the bits so every
zero becomes one, everyone becomes
a zero.
I go ahead and add one again.
One plus one is ten.
So I have my carry.
And then I go ahead and I convert
this into binary, so
it looks like I have a sixty four
plus a sixteen plus a four
plus a two, so I
add those all together that gives me
eighty six.
And we remember that we started off
with a one. Right, that told us that
we needed to convert it.
And so that means that this number
is negative.
Eighty six
in decimal form.
So in summary, today, we talked
about binary twos, complement
and then hexadecimal as a
representation.
Looking forward, we were going to
talk about instructions and then
logical operators.
If you have questions, you can
contact me at Miller, MJ at
Unclutter Aidoo and you can find
me at Twitter @
@ Milhouse 30.