13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 1.4 of Assembly.
So today we're gonna learn about binary two's complement and Hexi Decimal
So, by near is what a computer uses in order to store numbers. And it uses ones and zeros,
and each bit represents a powers of power of two. So we have to to the 0 to 2 the one to do the two and so on and so forth until we get to to to the seven.
So to do the zero represents the number one. And then we basically doubles to go down the line. 1248 16 32 64 128.
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 33 we're gonna go on down the line until we get to a number that is smaller than the current number that we have. So we have 33.
Well, I don't need 100 28. I don't need 64 but I do need a 32
and then we go ahead and subtract the two. So 33 minus 32 gives me one, and I can kind of shortcut and go down here toe one to say I do also need a one.
And so the number 33 would be 00100001
That would be its binary representation.
To convert from decimal, we take on binary number. We go ahead and write it down, and then we just right 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 a 128 plus 32 plus four plus one
by Adul those together I get 165. So the number 10100101 is 165 in decimal
So two's complement is what computers use in order to store both positive and negative numbers. And the top bit or most significant bit represents a 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 we're gonna convert from decibel into two's 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 two binary and then we're gonna flip all the bits. So every zero becomes one and everyone comes a zero,
and then we'll go ahead and add one to that. And that is the process to convert from decimal two two's Complement
to convert from two's complement to decimal.
So we have a binary number. If the most significant bit is a zero. We just converted to decimal, so it's a positive number. We just go ahead and convert it like we did before.
But if the most of name Gigabit is a one, we're going to convert it to binary.
Then we'll flip all the bits ever again. Every zero becomes the one everyone becomes zero,
and they were gonna add one,
and then we'll converted to decimal. But we got to make sure at the end that we add a negative sign to say that this number is a negative number.
So here's some binary addition, fax. So we got zero plus zero. We get zero, and I added a leading zero here.
One plus zero is 10 pose. One is one.
One plus one is two. But we're writing in and buying areas. We've got a zero
ones and we got one too. So we got 10
and then one plus one plus one is 11.
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 gonna go ahead and cover 42 to binary. So I need a 32 and an eight in a two. So I get to move my binary number and then we flip all the bits so you can see that every zero becomes a want and everyone becomes a zero.
And then we add one clear to the end, right? So
I have this, I say, plus one. So one plus one gives me
10 and all the rest of the bits remain the same.
And so negative. 42 in two's complement. Is this number right here? So 11010110
Hex or Hexi Decimal.
So Hexi Decimal is based 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 to give us zero or, for example, six.
So I got a 1248
So I got two plus four will give me six
within, For example, we got the number 10. So let's 10. 10 or an eight in a two. And that gives us the letter A
all the way through F Right. So one plus two plus four plus eight.
Well, give us 15.
And so one bite is gonna go ahead and be to Hexi Decimal dishes. Digits.
So again, we have the process of taking the number 42. We already did the first part of the process,
right? So I converted that in two's complement, and I got this number, 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 42 decimal two two's complement using Hex,
go ahead and do the whole process to convert to two's complement. And then we got to convert toe hex.
So I will take my number 1101 Go ahead and look it up in my table and it looks like 1101 is a D.
And then I look up my other number. 0110
I believe that is a six. And so the hex representation is
zero x. So this is the prefix we generally use for Hexi decimal numbers
and then d six.
So that represents the number
So now if I'm given the number zero x A and I'm going to convert that from Hexi Decimal two's complement into
binary star decimal.
So we take the number a A and we convert that from zero ac from Hexi decimal into binary.
So a is 1010 I'm gonna have another 11010
Then I flip all the bets. So every zero becomes one. Everyone becomes a zero. I go ahead and add one again. One plus one is 10. So I have my Carrie,
and then I go ahead and I convert this into binary. So looks like I have a 64 plus a 16 plus a four plus a two.
So I add those all together that gives me 86. 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. 86
and in decimal form.
So in summary today, we talked about binary two's complement and then Hexi Decimal 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 you and Kate. I e to you. And you can find me on Twitter at at Milhouse 30