Free YouTube Transcribe

Video transcript

Signed Binary Numbers

Steve Hollifield · 2,646 words · 13 min read

Want to search this transcript, jump the video from any line, or download it as TXT, SRT, or VTT?

Open in the transcript tool

Full transcript

0:02in this video I want to cover how to uh

0:05operate with signed binary numbers and

0:08how we handle signed binary numbers and

0:12then we'll mix in uh expressing those

0:14signed binary numbers in heximal format

0:18uh for the beginning let's look at

0:20unsigned binary real briefly and just

0:25recall that we do a sum of Weights

0:28method for um determining the value of a

0:33unsigned binary number so for example an

0:368 bit binary number might be and I'll

0:39just make it a small one uh there we go

0:42we have 000000 0 1 0 1 0 and we're

0:47saying that's an unsigned binary number

0:49well remember that there are Place

0:51weights for each binary bit position so

0:55this is the the one's Place 2 to the

0:57zeroth power uh we double that to the

1:00two's Place 2 to the first Power we

1:02double that to The Four's Place 2 to the

1:06um 2^2 and then the eights

1:1116s 32 64 and 128 Place recall that uh 8

1:19bit binary can house uh unsigned numbers

1:22between 0 and 255 to have a total of 256

1:27total uh combinations of peration there

1:30okay and so in this binary number we're

1:34just going to add the two uh Place

1:37weights where the uh binary number has a

1:40one in it or all of the place weights

1:42that uh have a binary one in them so

1:45that would mean that we would have an

1:46eight and we would have a two because

1:49they both have a binary one there so 8 +

1:522 that equals 10 and the base 10 decimal

1:56number system so 0 0 0 0 1 0 1 0 that 8

2:02bit binary number is equal to 10 in the

2:05decimal number system now of course with

2:08unsigned binary numbers uh we kind of

2:11recognize those as being positive

2:13numbers uh even though we don't say that

2:16because it's unsigned we just know that

2:18we don't have any negative numbers okay

2:21now when we move to uh signed numbers

2:25we're going to we're going to do a

2:27signed binary number then

2:31and I'm just going to take this exact

2:33same value uh 0 0000 0 1 0 1 0 as a

2:40binary number and since I am designating

2:43it as a signed binary number then the

2:47most significant bit this is the

2:50MSB this becomes the S bit for that

2:54number now this uh means that the number

2:58cannot um

3:00uh house as large of a value as an

3:04unsigned number can in other words

3:06unsigned went all the way up to

3:08255 now what we see is that we have

3:12these uh seven bits that uh for this

3:17particular number is going to give it

3:18its value and then the sign bit here a

3:22zero in the sign bit uh equals a

3:26positive number and a one would equal a

3:29negative number okay now this is

3:32skirting on what was uh what has been

3:35called signed magnitude notation and uh

3:40the way we actually use signed binary

3:43numbers in digital systems like our

3:45microprocessor is called tw's complement

3:48and so what we kind of learn at this

3:51point here is that that most significant

3:53bit is a as a sign bit when we glance at

3:57this number we look to that most

3:58significant bit if it's a zero it's

4:00going to be a positive number if it's a

4:02one it's going to be a a negative number

4:06okay so that tells us our sign now how

4:09do we evaluate the value of this this um

4:15signed binary number well same way as we

4:17did before we've got our place weights

4:19above it 1 2 uh 4 8 16 32 64 and 128

4:28that's the same as it as it is with

4:30unsigned uh however you and you'll

4:32notice here we've got a one in the e

4:34place and a two in the um in one in the

4:38two's Place excuse me and then that is

4:40going to equal

4:4210 uh in the decimal number system but

4:45we have this zero here that's going to

4:47come over and we're going to say that is

4:49positive 10 a signed positive number

4:53okay a signed binary number you say well

4:55that's exactly what we did before uh

4:59yeah but but it has limitations here's

5:02the limitation uh if I if I take a

5:05signed binary number to its it's maximum

5:08in the 8bit format then I would have uh

5:10for a positive number I would have 0 1 1

5:131 1 one one 1 okay uh what does that

5:18mean well that still means that this is

5:21a zero and it's going to be a positive

5:23number okay and so when we make this

5:26conversion I'm going to end up with a

5:27positive number and then what does we

5:30would add up all of these uh bit

5:33positions and when you add up 64 plus 32

5:36+ 16 842 and one you get 127 so positive

5:41127 is the largest positive uh signed

5:46binary number that we can have in 8bit

5:48format if we wanted to go above uh 127

5:52in the positive direction then we would

5:54have to have more than 8 Bits why you

5:57say well if we uh if we add one to this

6:01then we would end up if we added one to

6:03it we would end up with this

6:07number and notice that when we add one

6:09to that and I'll go through this in

6:11length I won't just skip over that so

6:13I'm going to add one I'm going to do

6:14this in good old long hand uh notation 1

6:17+ 1 is two and one zero in binary is a

6:21two so we put down the zero carry the

6:23one it's kind of like 9 + 1 is 10 so

6:25zero carry the one and then we've got

6:28the carry plus one would be two 0

6:30carryer 1 0 carry one that's going to

6:32keep on happening all the way out and

6:36then uh we're going to have one more

6:39time and then we're have 1 plus 0 is one

6:41so there is the value and now what do we

6:46have well I have what's called two's

6:48complement overflow I have and that is

6:50one of our one of our uh sign bits in a

6:54microprocessor one of our condition code

6:56bits in a microprocessor that tells us

6:58that we've had a a carry from the uh 7th

7:02to the eighth bit and that means that we

7:06had a carry that went into the sign bit

7:08location and Chang the sign of the

7:10number or had the potential to change

7:12the sign of the number and so in this

7:15case it did and you see that now we have

7:19uh a negative number but well I had 127

7:22positive and I added one to it I should

7:24have 128 well uh in sign notation when

7:28we have our sign number systems to's

7:30compliment if we had that tw's

7:32compliment overflow we blew away our

7:34sign bit in the 8 bit format and so

7:37that's what I'm saying you'd have to go

7:38to like a 16bit number or a 32bit number

7:42in order to have those larger um those

7:46larger values in the sign number system

7:49uh let's we've looked at the positive

7:51end up to the limit from0 to

7:54127 and now let's look at how a negative

7:58number works in the sign number system

8:01and so I I'll give you a negative number

8:04um and this we'll start out with the the

8:08smallest of the negative numbers in 8

8:10bit format and so this is uh

8:1611111111 uh if you're looking at groups

8:18of four there uh it' be FF in heximal if

8:22you were typing that into a heximal

8:25entry for eight bits but um here we've

8:28got uh this value and immediately it's

8:31not really all that um all that uh

8:35apparent what the actual decimal value

8:38of this is I can tell it does have a one

8:40and the sign bit so I know it's equal to

8:42a negative number I've got that one in

8:45the most significant bit position uh but

8:48what is the value of it well if you uh

8:52one analogy is if you went and bought a

8:55a brand new car and I know with digital

8:57odometers this is kind of

9:00uh impossible but if you bought a if you

9:02had a brand new you know 1957 Chevy um

9:06it would have the old mechanical

9:08odometer on it and it would have zero

9:11miles and if you uh put that car in

9:14reverse and drove your first mile

9:16backwards uh that odometer would roll

9:19back to

9:219999999 uh and you would have all nines

9:24there uh and and and uh you would have

9:28driven negative 1 miles well that is

9:31exactly what's happened here in binary

9:33of course we only got zeros and ones in

9:34binary but if we take zero and we

9:37subtract one from it then we would have

9:40negative - one and we would have rolled

9:42back to all ones one one one one one one

9:45just like we have on screen now there's

9:47a uh there's a way to uh kind of

9:50mathematically take care of we don't

9:52have to necessarily count backwards step

9:54by step to do it uh to make that

9:56conversion we can use a shortcut method

10:00uh where we count over two and including

10:03the first one that we encounter from

10:05right to left so I'm going to count from

10:07right to

10:09left okay and uh from so coming from the

10:13right here I'm going to um copy down the

10:17over two and including the first one I

10:19come to which is the very first bit in

10:21this case and uh then I'm going to uh

10:25complement or uh invert all of the uh

10:30bits after that so every bit I come to

10:32after that this one becomes a zero and

10:34this one becomes a zero this one becomes

10:36a zero 0 0 0 0 okay and then I can see

10:42that I can do sum of Weights method to

10:44convert this from decimal to Binary and

10:47obviously it's just a one so that means

10:50that this bit pattern I keep my negative

10:54okay I write down my negative and then I

10:56take this as my magnitude

11:02all right and it just brings my one over

11:05here so this bit pattern is equal to -1

11:09okay I'll try that with one that's a

11:11little more interesting that's got a

11:13little more um uh a variety of bits in

11:18it instead of just all one so we'll make

11:20sure it's a negative number so I'll

11:21start with a one there and let's see uh

11:25we'll go uh 0 1 1 0 0 0 0 how's that

11:33okay now so what is that value uh I can

11:36tell it's a negative number because the

11:38most significant bit here is is a one so

11:41that means it's going to be negative so

11:42over here I can say okay that's going to

11:44be a negative

11:45number all right um now I'm going to use

11:49that shortcut method of two's complement

11:53uh converting over to tw's complement so

11:55I'm going to do my my

11:56twos

11:58complement

12:01shortcut

12:03method and so I'm going to copy over two

12:06from right to left I'm going to copy

12:09over to an including the first one I

12:11come to so it's going to be 0 0 0 0 1

12:15and then I'm going to invert all the

12:17rest of them so this will become this

12:18one will become a zero this zero become

12:20a one and this one will become a zero

12:23now that kind of converts it back to

12:26unsigned if you will and now I can just

12:29add up the place weights and get the

12:30magnitude for my negative number that I

12:33have up here okay so uh I'm interested

12:37in this the the signed Worth or signed

12:42value of that number right there that I

12:44Circle so um now we've got the uh ones

12:49twos fours eights 16 32 64 and 128's

12:56place so I've got a 64 here okay I've

13:00got a

13:0116 and that's it that's all I have to

13:04add is 64 + 16 and that's 80 isn't it

13:08okay so -80 is the base 10 is the

13:13decimal equivalent s decimal equivalent

13:15of that tw's complement number so all of

13:19this together I can put a big uh big

13:21title up here twos complement side

13:25numbers

13:29okay that's our that's our title for the

13:31whole thing and um this is the the

13:35shortest to the point methodology of

13:38being able to make that conversion now

13:42uh up here for this top one up here uh

13:46if if I wanted to group those in groups

13:48of four and say well what is -1 equal to

13:53and um binary shifted to the the heximal

13:58format then 1111 is going to be F and

14:01111's going to be F so if I were

14:04entering that into a digital system and

14:07hexadecimal format I'll just put base 16

14:10there uh then I could just type in FF I

14:13get that bit pattern and in a tw's

14:15compliment signed environment

14:17programming environment it would be

14:19equal to -1 and I didn't put my little

14:21decimal 10 there so there you go

14:24um base 10 so FF is1 and and in binary

14:30it's uh eight ones in a row there okay

14:33uh for this one down

14:35here let's see what do we got there we

14:37got uh eight for this for this we've got

14:41a zero there for hexadecimal and then

14:44one0 1 0 that's 11 which is B 8 + 2 is

14:5010 1 is 11 which is B so

14:54b0 base 16 okay that' be our hexadecimal

14:57for that one which is equal to 80 in the

15:00decimal number system uh so uh doing

15:04that is um um a an essential skill in in

15:10in handling signed uh binary numbers now

15:15um how large of a negative number uh can

15:20can we um can we house well actually uh

15:25what we had there earlier as an example

15:28if we had one and all Zer after it one

15:33and seven

15:34zeros um we see that this is uh this is

15:38a binary and so this is our negative so

15:41I put my negative over here and then I'm

15:43going to do my tw's compliment

15:45conversion on it uh copy over to an

15:48including everything uh over to an

15:51including the first one and then

15:52inverting everything else well the first

15:54one is the S bit itself so I'm just

15:56copying all the way over to here

16:00like that and if I do the ones 2os fours

16:048 16 32 64 this is the 128's place so uh

16:10I've got one 1 * 128 so 128 is that

16:15value okay and so my number line uh

16:20would go from uh positive

16:25127 have zero in the middle and I'd have

16:2812 a so if you if you look at that all

16:32encompassing uh from uh paused most for

16:368 Bits uh for 8 Bits this is the entire

16:39number line and you have 256

16:42possibilities there and you have uh

16:45basically you've basically taken

16:47unsigned over here that went from 0

16:50through

16:52255 and you split it down the middle and

16:54made half of them on the left positive

16:57and half of them on the right uh

16:59negative and so that is uh and you had

17:02to have a place for zero to live as well

17:05so that takes care of uh shifting that

17:08unsigned uh range over and making it

17:12balance around zero half of them

17:14positive and half of them negative

More from Steve Hollifield

Recently added transcripts

Browse the whole transcript library

This transcript was generated from the captions YouTube publishes for this video. Get the transcript of any YouTube video atfreeyoutubetranscribe.com, free, unlimited, no sign-up.