Transcript for:
1.2 Understanding Binary and Decimal Conversions

now let's look at another example in this case we'll look at something a bit easier we'll have 101 base 2 so there's no fractional part this time just a whole number part so as usual we'll number the positions 0 1 and two and so this is equal to 1 * 2 to second power plus 0 * 2 to the 1st power + 1 * 2 to the zeroth power and 2 2ar is 4 2 to the first power is 2 but 0 * 2 is 0 and 2 to the zeroth power is 1 and 1 * 1 is 1 so we have 4 + 0 + 1 which is equal to 5 in base 10 so the binary number 101 base 2 is equal to 5 base 10 now let's work on one final example of converting binary to decimal and I hope that you'll try this one yourself first uh I want to challenge you with this we have the binary number 1010101 one base 2 you try to find the decimal equivalent of that so I hope that you'll stop the video for a moment try to work this yourselves and then we'll come back and do it all together okay uh proceeding in the normal fashion we'll start numbering the positions uh 0 1 two and three for the whole number digits and negative 1 -23 for the digits representing the fractional part so we have 1 * 2 cubed 0 * 2^ 2 1 * 2 to the first Power 0 * 2 to 0 of power we have these four terms here and then one this one here 1 * 2 -1 0 * 2 -2 1 * 2 -3 and you see that written down here now 2 cubed is 8 and 1 * 8 is 8 2^ 2 is 4 but 0 * 4 is 0 2 to the first power is 2 and 1 * 2 is 2 2 to the zeroth power is 1 but 0 * 1 is 0 2 to the - 1 is 0.5 1 * 0.5 is 0.5 2 to the -2 is .25 but 0 * that is zero and finally 2 to the -3 is125 and 1 * that is .125 and if we add all of these numbers up we get 10.625 so we conclude that this binary number 1010101 base 2 is equal to the decimal number 10.625 base 10 so that concludes our discussion of converting binary numbers to decimal numbers and now now we want to go the other way around learn how to convert a decimal number to a binary number so we'll start with something that we have just calculated but in the other in the opposite direction let's suppose that somebody ask us what 10.625 base 10 is equal to when we go to Binary now of course since we just went uh since we just did this problem we know the answer is 1010101 base 2 we know that but let's see how we could arrive at this answer if we didn't know it already well uh the way that we're going to do this is called an iterative technique and you might say iterative technique for converting from base 10 to base 2 now the way this iterator technique works is a following we write down the whole number part of the number over here to the left so you have we have 10.625 the whole number part is 10 write that down on the left and write down 625 over on the right now for the whole number part we repeatedly divide by two so 10 / two gives us five with a remainder of zero and notice that I've put R here at the top of a column and that's going to be my remainder column and so since when I divide 10 by two I get five with the remainder is zero I'll put my first entry in the remainder column will be zero now when I divide five by two I get two and a remainder of one so this time I put one in the remainder column now when I divide this two by two I get one with a remainder of [Music] zero and finally when I divide one by two two won't go into one at all so I get zero with the remainder of one now you stop this procedure stops when you get a zero here in this column so since we found a zero here in this column on the left we stop and we now look at our remain column from the bottom to the top and we have 1 0 1 0 what this tells us is that when we write this number in binary the whole number part will be one Z 1 0 as we can see down here now how do we get the fractional part well over here we have 625 and instead of repeatedly dividing by two as we did with the whole number part now we will multip LLY by two so if we take 625 and multiply by two we get 1.25 the whole number part I'll split off over here is one and then we also have 0.25 now the one I'm just going to keep to the side but the .25 I'll carry down to the next line 0.25 * 2 would be 0.5 so I'll write down the whole number part zero and then the 0 five here and then one last step if I take this 05 down here and have 0.5 and again multiply by two this time I'll get 1.0 so the whole number part is one the fractional part is zero and when the fractional part is zero here that tells you to stop and so we have here in this column 1 Z 1 this column we read from top to bottom one1 and there you see one Z1 and here is our final answer 1010101 and in fact if we scroll above that is exactly what we had before so this is indeed the boundary equivalent of 10.625 base 10 that's a of course A New Concept maybe uh it seems a little bit tricky and so let's look at another example let's take for instance maybe something like um 63 75 so we now want to convert this number 63.75 base 10 to a binary number well once again we'll write the whole number part on the left 63 and the fractional part over here to the right 0.75 again we want to use iterative technique so we will repeatedly divide the whole number part by two and I'm going to go ahead and put down an R for the remainder column so if we divide 63 by two we will get 31 with a remainder of one and we divide 31 by two we will get 15 with a remainder of one if we divide 15 by two we will get seven with a remainder of one if we divide seven by two we will get three with a remainder of one if we divide three by two we will get one with a remainder of one and finally if we divide one by two we get zero with the remainder of one and if we read these numbers from bottom to top we have one one let's see one two three four five six ones so the whole number part will be 1 one one one one one now let's look at the fractional part now remember here we will repeatedly multiply by two well 0 75 * 2 is 1.5 so we write the fractional part here and the whole number part here 0.5 + 1 and we'll take the fractional part to the next line 0.5 * 2 is what that's 1.0 so the fractional part is zero and the whole number part is one and remember when the fractional part here is zero that tells us to stop and now we read these numbers from top to bottom and it's 1 one so here is our answer 63.75 base 10 this number here in base 10 when we convert it to Binary we get 11111111 base two this iterative technique um can be used not just for converting from decimal to Binary but from decimal to other number systems as well for instance suppose that we wanted to convert let's say the number 15 base 10 into a base three number well we could proceed with iterative technique here as well now in this case there's no fractional part so all we have to do is write down the whole number part and then have a r column and we need now to repeatedly divide by three rather than by two so for instance if we divide 15 by 3 we would get five with a remainder of zero 5 ided 3 would be one with a remainder of two and then 1 / 3 would be 0 with the remainder of one and now since we have a zero here in the left column the procedure uh is terminated and we look from bottom up and we would conclude that the answer is 1 two 0 base three so 15 base 10 is equal to 12 base three and if we want to check that we can use the same procedure we used earlier for converting from binary to decimal uh but with a little modification now since we're in base three rather than base two so the way we would do that is we would say well one two 0 base three we number the positions 0 1 2 and therefore 1 120 base 3 is equal to 1 * 3^ 2 + 2 * 3 to the 1 power + 0 * 3 to the zeroth power well 3^ 2ar is 9 and 1 * 9 is 9 3 to the first power is 3 and 2 * 3 is 6 3 to the zeroth power is 1 and 0 * 1 is 0 and then finally 9 + 6 is 15 and indeed this agrees with what we have over here on the left so there is an example of converting decimal number 15 base 10 to a Turner number or base three number one two 0 and then going back again to check it so we have these two techniques for converting from one a number system to another now in some instances there is an easier way to do things but it uh this this uh other technique only applies in special circumstances so let's see what that would be let's suppose that we had the number 1 0 1 0 1 1 0 base 2 and we wanted to know what this is in base 8 well since 8 is 2 to the 3 power this technique will only work if one base is equal to the other base to some power but in this case that is the situation 8 is equal to 2 to the 3 power and therefore the technique would be as follows we start here at the point and since we have that 8 is 2 to the 3 power we will group the numbers in groups of three as follows so the first group of three as you can see here is 1 one0 the second group is 0 one 0 Z Now the uh the last group as we number as we're going from left left right to left we just have a one so we could add two zeros to that and make that a one now how do we finish this up well 0 01 is one 0 one0 in base two is the same as two and one Z is six and therefore here is our answer we have that 1 0 1 0 1 1 0 base 2 believe it or not is equal to 1 26 base 8 and again the way we got that was just by observing that 8 is equal to 2 the 3 power and then we took the digits in the binary number in groups of three and converted each group separately uh to the appropriate number in base eight now you're probably skeptical about this uh you might not believe that it gives us the right answer but let's check and see well uh we can number our positions in each of these numbers so the number on the left is equal to 1 * 2 to the 6th power + 0 * 2 to the 5th power + 1 * 2 4th power + 0 * * 2 cubed + 1 * 2^ 2ar + 1 * 2 to the 1 power + 0 * 2 to the Z power and on the other hand this number on the right is equal to 1 * 8^ 2ar + 2 * 8 to the first power + 6 * 8 to the 0 power now let's check both of these numbers and see if they are equal to each other well 82 is 64 so this is 1 * 64 which is 64 8 to the first power is 8 and 2 * 8 is 16 and finally 8 to the zero power is one and 6 * 1 is 6 so the number on the right is 86 in base 10 now let's check the number on the left 1 * 2 to the 6 of course is 64 0 * anything is zero 2 to the 4th is 16 so 1 * 16 is 16 0 2^2 is 4 2 to the first power is two 0 * anything is zero and if you add up all those numbers sure enough you get 86 base 10 so indeed this technique that we have shown here for converting from base two which is called binary to base8 which is called octal this technique does work but it only works again this technique will only work when the two when one base is a power of the other base one thing you may have noticed is that when we're working in a certain base all of the digits that we use will be less than that basee let me explain you what I mean for instance when we're working in base 10 it might well we might see a number like this for instance or we might see we'll say this is base 10 we might see a number like this but you notice that each one of those digits that we use is less than 10 uh what I mean uh to be certain this is clear six is certainly less than 10 nine is less than 10 8 is less than 10 7 is less than 10 1 is less than 10 2 is less than 10 5 3 9 1 and two are all less than 10 if we want to represent the number 10 of course we take two digits to do it we write a one and a zero now similarly if we're writing in base two we write we would have something like this or we might have something like that again all of the digits in this case are less than two and if we want to write the number two itself we would again write one zero so in any number whenever we're writing in some base our digits will go all the way up to that minus one so in other words when we're writing in 10 the largest digit that we have is nine when we're writing in base two the largest digit we have is one you remember when we had numbers in base 8 we could have something like this for instance 167 base 8 or uh perhaps um 5 2 3 7 base 8 we have all the numbers up to eight but not including eight but that raises an interesting question what about when we have base 16 now the reason that this is sort of interesting is that if we're going to have digits for every number up to the base minus one then that means we must have digits for every number up to 15 however we don't know of a single digit that represents 15 I mean if we're in other words if we're running a base 10 we would need to use two digits to represent 15 we would made a one and a five but when we're writing in in hexad decimal or base 16 we don't want to write one and a five because if we wrote for instance one and a five base 16 well that not going to be 15 in base 10 right in fact it would be equal to 1 * 16 to the 1st power + 5 * 16 to the zeroth power so this would be 16 + 5 and it would be equal to 21 in base 10 so we're asking the following question if we want to write 15 and base 10 15 base 10 or our regular old 15 if we want to write that in hexad decimal how do we do it and there's no way to figure this out you have to Simply know the answer and so let me give you the answer if we want to write base 16 numbers uh well let me back up and say this situation arises for only a few base 16 numbers and let's see how it goes so if we're if we're looking at base 10 and base 16 and we're looking at uh the numbers zero and base 10 is written as zero in base 16 one in base 10 is the same as one in base 16 same is true for 2 3 4 5 6 7 8 and nine they are the same in decimal and in base 16 we just got hexadecimal but what about 10 in base 10 now we don't want to write one zero in base 16 because as we know that would be equal to 1 * 16 to the 1st Power Plus 0 * 16 to the zeroth power and that would be equal to 16 in base 10 but we want a number in we we want to find a one-digit expression in base 16 that will equal 10 in base 10 and what people have chosen to be uh that on digigit representation is a and likewise for1 we have B 42 we have C for 13 we have D for 14 we have e and for 15 we have F and finally when we get to 16 then we have one Zer for 17 base 10 that's equal to 11 one base 16 Etc so to make sure that this concept is clear to you let's suppose that we had the heximal number um d12f base 16 and we wanted to know what that is equal to in base 10 well we can number our positions and so this is equal to D * 16 16 to the 3 power + 1 * 16 2 + 2 * 16 to the 1 power plus ftimes 16 to the zeroth power now d d is equal to 133 and sorry I had to go get a calculator we'll find out what 16 cubed is now okay 16 cubed is 496 16 SAR is 256 2 * 16 would be 32 and then f is equal to 15 and 16 to the zeroth power is 1 so we have 15 * 1 13 * * 496 is 53248 and then 1 * 256 is 256 32 and 15 and so we finally get 53,000 551 base 10 so again to summarize that d 1 2 F 16 the hexad decimal number D12 F16 is equal to 53 5 five 1 B 10 now just to um well we could check this uh this will this actually is a little since this number is so big it would be a little tedious to check this so let me give you a somewhat U easier example and I'll show you an easy way to check it so let's look at something uh a little easier let's say maybe U 3 D2 base 16 is equal to what in base 10 I hope that you'll stop the video for a moment and try this yourself and then we'll look at it together okay so let's see how we would convert this to base 10 and then we'll see how we can uh check our work okay um well we numbered the positions as usual 0 one and two so the number here on the left is 3 * 16 2ar + D * 16 to the first power + 2 * 16 to the 0o power well as we said before 16 s is 256 and 3 so we have 3 * 256 plus now D if we look above D is equal to 13 so that's 13 * 16 + 2 * 16 to the zeroth power is 1 so 2 * 1 and this will give us 768 plus 208 plus [Music] two and we get 978 so we we are concluding that 3 D2 base 16 is equal to 978 base 10 uh now you might be wondering about an easy way to check this and let me show you what it would be or I'll I'll show you one easy way to check it and our plan will be this we will convert 978 base 10 first to Binary and then to hexadecimal and uh you might be wondering why I'm taking this roundabout way of doing it well the reason I'm first going to go to Binary is we've already learned how to do that we've learned the iterative technique for converting decimal to Binary now of course we could use that same technique remember we said that the Itor technique doesn't have to have decimal and binary it could be used for other bases as well so we could use the itative technique for for going directly from base 10 to base 16 but I want to show you let's have one more review on using the iterative technique to go from decimal to Binary that'll be useful because we'll review something we've already done and then going from binary to hexad desimal we'll use that special technique that we used before to go from binary to octal in other words since since 2 and 16 since 16 is a power of two we'll be able to use the same kind of Technique we did earlier to go from binary to hexad decimal that we did earlier to you go from binary to octal so let's see how this goes so first we're going to go from 978 base 10 uh uh to uh binary okay well there's no fractional part so there's just a whole number Part 9 78 and we'll have a remainder column and let's see how this goes well if we divide 978 by two we get 489 with a remainder of zero if we divide 489 by two we'll get 244 with a remainder of one if we divide 244 by two we'll get 122 with a remainder of zero 122 / 2 be 61 again with a remainder of zero 61 / 2 will be 30 with a remainder of one 30 ided two will give 15 remainder of zero 15 / 2 will be 7 with a remainder of 1 7 ID 2 will be 3 with a remainder of one 3 / 2 will be 1 with a remainder of 1 and finally 1 / two will be zero with a remainder of one and remember when we get a zero there that tells us that the iterative technique at least for the whole number part has finished and remember that we will read when we're looking at the whole number part we read from bottom to top when we're looking at the fractional part we read from top to bottom so since this is the whole number part we will read from bottom to top and we conclude that that 978 base 10 is equal to one one one one we have four ones and then a zero and a one and then two zeros and a one and a zero two zeros a one and a zero so 978 base 10 is equal to 11 one1 0 1 00 0 1 0 base 2 that is the first part of what we wanted to do we have converted 978 base 10 as a decimal number we've converted it to Binary now the conversion from binary to hexadecimal is very simple because 16 is 2 to 4th power and therefore we will group these numbers into groups of four digits we have four digits there four digits here and if we put two zeros in front then we can have four digits there and now we will write down the appropriate numbers for that one one and binary or excuse me 0 011 in binary that first number 0 011 is two and one or three the second number 1 1 01 we'll just think about that that's 8 and 4 is 12 and 1 12 and 1 is 13 but 13 in hexadecimal is D so we have D for that part and then finally 0 01 1 Z that's equal to two so we have 3 D2 base 16 and sure enough as you can see up here that is the original number that we started with so 3d2 base 16 sure enough is equal to 978 in base 10 and we've shown that and two different ways so this gives you a good bit of practice in converting from one number system to another and now we're ready to discuss the uh first two problems uh in fact let's just say uh one problem this time one problem on your uh quiz excuse me first test I should say test okay so the problem uh will be the following problem one for test one uh we want to um actually I guess maybe there will be two problems so right 12317 base 10 in binary oh wait I see that this is a problem right away because you haven't learned quite enough to do that so uh let me let me modify this problem uh let's stop for just a moment and then we will resume now let's try that again I'm ready now to give you two problems for test number one and then in our first formal lecture or excuse me in our first real meeting uh I'll give you uh probably another problem to do but the first two problems are these so for the first problem on test number one uh what I'm interested in is having you convert the decimal number 13.25 to a binary number and I'll give you four choices here is the answer one [Music] one01 base 2 1 one 0 0.01 base 2 1 one 0 1 1 1 base 2 or 1 1 0101 base 2 you need to pick one of those and make a record of it so that you can uh record it uh online at the appropriate time now for for problem 1.2 uh I want you to tell me 77 the the decimal number 77 base 10 is equal to what in hexadecimal and again I'll give you four choices is the correct answer 3F B 16 or 4 d base 16 or 21 base 16 or 37 base 16 so once again now you should work these two problems and make a record of your answers and uh as soon as the next class period begins you'll have the opportunity to record your answers online and you will be shown in class how to do this so uh good luck and I'll talk to you soon