### Video Transcription

00:01

Hello. This is Dr Miller, and this is Episode 1.4 of Assembly.

00:06

So today we're gonna learn about binary two's complement and Hexi Decimal

00:11

binary.

00:13

So, by near is what a computer uses in order to store numbers. And it uses ones and zeros,

00:19

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.

00:29

So to do the zero represents the number one. And then we basically doubles to go down the line. 1248 16 32 64 128.

00:40

And when we're converting, we basically add up all these numbers in order to get our decimal number.

00:45

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.

00:54

Well, I don't need 100 28. I don't need 64 but I do need a 32

00:59

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.

01:07

And so the number 33 would be 00100001

01:14

That would be its binary representation.

01:18

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.

01:26

And everywhere I have a one that means I want to include that.

01:29

And so I need a 128 plus 32 plus four plus one

01:34

by Adul those together I get 165. So the number 10100101 is 165 in decimal

01:46

two's complement.

01:48

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.

01:57

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,

02:07

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.

02:15

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,

02:24

and then we'll go ahead and add one to that. And that is the process to convert from decimal two two's Complement

02:32

to convert from two's complement to decimal.

02:36

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.

02:45

But if the most of name Gigabit is a one, we're going to convert it to binary.

02:49

Then we'll flip all the bits ever again. Every zero becomes the one everyone becomes zero,

02:53

and they were gonna add one,

02:57

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.

03:06

So here's some binary addition, fax. So we got zero plus zero. We get zero, and I added a leading zero here.

03:14

One plus zero is 10 pose. One is one.

03:17

One plus one is two. But we're writing in and buying areas. We've got a zero

03:23

ones and we got one too. So we got 10

03:28

and then one plus one plus one is 11.

03:30

I mean that you can go and tell your kindergartner that one plus one plus one is 11 and see what they think.

03:38

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.

03:58

And then we add one clear to the end, right? So

04:00

I have this, I say, plus one. So one plus one gives me

04:05

10 and all the rest of the bits remain the same.

04:10

And so negative. 42 in two's complement. Is this number right here? So 11010110

04:21

Hex or Hexi Decimal.

04:24

So Hexi Decimal is based 16 and it allows us to represent binary numbers using the letters zero through nine and a through F.

04:35

And so we can see the

04:36

binary representation and then the hex number.

04:41

So again, this is just converting from binary to decimal will give us all zeros to give us zero or, for example, six.

04:47

So I got a 1248

04:50

So I got two plus four will give me six

04:54

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

05:02

all the way through F Right. So one plus two plus four plus eight.

05:08

Well, give us 15.

05:10

And so one bite is gonna go ahead and be to Hexi Decimal dishes. Digits.

05:15

So again, we have the process of taking the number 42. We already did the first part of the process,

05:20

right? So I converted that in two's complement, and I got this number, this number down here

05:29

and I put a space in here so that we could see the hex digits relationship so

05:32

you'll go ahead. And if you're converting that into from

05:36

the number negative 42 decimal two two's complement using Hex,

05:43

go ahead and do the whole process to convert to two's complement. And then we got to convert toe hex.

05:46

So I will take my number 1101 Go ahead and look it up in my table and it looks like 1101 is a D.

05:55

And then I look up my other number. 0110

05:59

I believe that is a six. And so the hex representation is

06:03

zero x. So this is the prefix we generally use for Hexi decimal numbers

06:09

and then d six.

06:12

So that represents the number

06:14

negative 42.

06:18

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

06:28

binary star decimal.

06:30

So we take the number a A and we convert that from zero ac from Hexi decimal into binary.

06:36

So a is 1010 I'm gonna have another 11010

06:43

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,

06:53

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.

07:01

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.

07:10

And so that means that this number is negative. 86

07:14

and in decimal form.

07:18

So in summary today, we talked about binary two's complement and then Hexi Decimal as a representation.

07:27

Looking forward, we were going to talk about instructions and then logical operators.

07:32

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

### Up Next

### Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

### Instructed By

Matthew Miller

Instructor