 So, at the end of yesterday's class there were a lot of questions about floating point decimal and all of that. So, what I am going to do today is I am going to spend the first 5 or 10 minutes just trying to clarify several of the issues that came up yesterday. So, I guess if I write something like, so this was one of the questions yesterday 9.875, how do you represent it is a floating point number in the representation. So, first let us try to see how would we represent it as just a binary number. So, this 9 I hope nobody has a doubt that it is 1001. So, this is just like an integer. So, the question is what happens with this 0.875, how do I represent it in binary? So, let us see, so let me take the number, so you know this is 9.875 which means what? This is 9 times 10 raise to 0 plus 8 times 10 raise to minus 1 plus 7 times 10 raise to minus 2 plus 5 times 10 raise to minus 3. And if you look at these powers of 10 over here, these exponents, these tell you exactly where the decimal point in this case, since this is base 10, so it is a decimal point. These tell you exactly where the decimal point is and which of these digits appears where? So, something that is multiplied with 10 raise to 0 will appear immediately to the left of the decimal point, something that is multiplied with 10 raise to minus 1 will appear immediately to the right and so on. And in fact, there was a question yesterday that if I divide 9.875 by 10, why is it that the decimal point moves to the left? Does everybody agree that 9.875 divided by 10 is 0.9875, right? So, the decimal point moves to the left if I divide by 10 and it moves to the right if I multiply by 10, right? So, there was a question yesterday after class that why does that happen? So, well, if you agree that 9.875 is this, so then if I divide by 10, I will have to divide this whole thing by 10, right, because 9.875 is just this. If I divide this whole thing by 10, what does it turn out to be? It is 9 times 10 raise to minus 1 plus 8 times 10 raise to minus 2 plus 7 times 10 raise to minus 3 plus 5 times 10 raise to minus 4. So, if you agreed that this corresponded to 9.875, I hope you will agree that this will correspond to 0.9875, right? This is just like the multiplier of 10 raise to minus 1 was the digit immediately after the decimal point. So, the multiplier of 10 raise to minus 1 should be the digit immediately after the decimal point, right? So, if I divide this by 10, then this is what I get and therefore, now I can read it off from here. So, multiplier of 10 raise to minus 1 is the stuff immediately after the decimal point, 10 raise to minus 2 is at 2 places to the right of the decimal point, multiplier of 10 raise to minus 3 is 3 places, multiplier of 10 raise to minus 4 is 4 places. So, is this ok? And similarly if I multiplied this number by 10, 9.875 times 10 would be 9 times 10 raise to 0 plus 8 times 10 raise to minus 1 plus 7 times 10 raise to minus 2 plus 5 times 10 raise to minus 3 times 10, right? And what is that? That is 9 times 10 raise to 1 plus 8 times 10 raise to 0 plus 7 times 10 raise to minus 1 plus 5 times 10 raise to minus 2. And by our same convention, the multiplier of 10 raise to 0 is the stuff immediately to the left of the decimal point. So, the multiplier of 10 raise to 1 would be one place to the left of it. This will be one place to the right of the decimal point and this will be 2 places to the right of the decimal point. So, therefore, 9.875 into 10 is 98.75 times 10. Is this clear? So, this is why when you divide by 10, the decimal point moves one place to the left, you multiply by 10, decimal point moves one place to the right. Well now, there is nothing sacrosanct about 10 over here. The same thing would happen by started doing things in binary. So, just as an example, suppose I give you 101.11, some binary number. Let us say we do not care what this binary number is. So, what does this represent? This is 1 times 2 raise to 2 plus 0 times 2 raise to 1 plus 1 times 2 raise to 0 plus 1 times 2 raise to minus 1 plus 1 times 2 raise to minus 2. Same idea. It is just that the base is 2. And now suppose I say I want to divide this by 2, whatever number this represents, I want to divide that by 2, which would mean take this and divide it by 2. The whole thing. So, what would that be? That would be 1 times 2 raise to 1 plus 0 times 2 raise to 0 plus 1 times 2 raise to minus 1 plus 1 times 2 raise to minus 2 plus 1 times 2 raise to minus 3. So, now, how should this number be represented in binary? The multiplier of 2 raise to 0 is the stuff immediately to the left of the point. It is no longer a decimal point because the base is 2. So, this is a binary point now. The multiplier of 2 raise to 1 is another place to the left. Multiplier of 2 raise to minus 1 is one place to the right of the binary point. Another one, another one. So, what has happened? I took this number divided by, I got this number. See the binary point moved one place to the left, just like when we take a decimal number divided by 10, the decimal number moves one place to the left. Is this clear? There were several questions yesterday after class about why is it that when we divide something by 2, the binary point moves to the left. This is the reason. And by the same argument, if you multiply this number by 2, the binary point will move one place to the right. So, there is nothing very special about the base 10. What is happening with 10 as far as movement of the point is concerned? The same thing is going to happen with 2, except that there you are multiplying by powers of 10. Now, we are going to multiply or divide by powers of 2. Is that clear? So, now let us come back to the original question. So, we said 9.875 and we could represent 9 using 1001. We want to know what 0.875 would be binary. So, what would be 0.875 in binary? This is the number that is less than 1. So, what we could do is, we could say to first represent this in binary, let us try to multiply it by 2. So, I will show the multiplier over here and let us remember that we have multiplied by 2. So, which means I will do this. Is it clear? So, I am just multiplying by 2, dividing by 2. Why am I multiplying by 2? To get this guy to become something more than 1, so that we can then represent the part to the left of the decimal point in binary. So, what happens if you multiply 0.875 by 2? What is it that you get? Yes, 1.75. So, the number 0.875 is therefore, 1.75 into 2 raise to minus 1. Now, as far as this 1.75 is concerned, you have this 1 over here which was just like this 9 to the left of the decimal point. So, we will say that ok, from here I know that it is going to be 1 plus something and then that has to be multiplied by 2 raise to minus 1. So, that something here is once again less than 1. So, now what I am going to do is, so I will write it as 1 plus 0.75 times 2 raise to minus 1. Now, once again this 0.75 is less than 1. So, I am going to take this whole thing 1 plus 0.75, I am going to put another multiplier of 2 here because I want to get this to something greater than 1 that I can represent and so I have to make this 2 raise to minus 2 because I have multiplied another 2, I have to divide by another 2 right. Now, this number 1 that was there, so I am multiplying it by 2 as well in the process of multiplying this 0.75 by 2 right. So, now this number 1 we saw in binary is represented by just 1. So, if I multiply this thing by 2, what is going to happen? The binary point will just shift 1 place to the right. So, I will get 1 0 right, this is what we just saw multiplying by 2, it is a binary point 1 place to the right. So, if the number 1 is represented as 1.0, so 2 times 1 will be represented as 1 0 point right and so this is you know whatever I will say 1 0 point plus I mean this is of course, in binary plus this is now 1.5, this is in decimal and this is 2 raise to minus 2. Now, once again from this 1.5, I can figure out what the integer part is right and I can express it in binary. So, this is 1 0 point in binary plus this 1 will be just 1 point in binary plus 0.5 in decimal right. I am sort of mixing binary and decimal. So, you can see how the binary representation is gradually built and this is still in decimal. So, I am keeping the fractional part always in decimal into 2 raise to minus 2, is that clear right. So, now what is this 1 0 point in binary plus 1 point in binary. So, there is a system of doing binary addition where you can add to binary numbers and figure out what the result is in binary, but for the time being let us just convert it to decimal, add them and convert that number back to binary. So, this is 2 plus 1 3 and let us convert 3 back to binary which will be 1 1 right. So, we will have 1 1 in binary 0.5 in decimal multiplied by 2 raise to minus 2. So, we will have 1 1 in binary 1 1 point rather in binary plus 0.5 in decimal and we have to multiply this by 2 raise to minus 2 fine. So, now once again that 0.5 is a fractional part. So, what I am going to do is I am again going to multiply by 2 ok. So, I will say 2 times 1 1 in binary plus 0.5 in decimal times 2 raise to minus 3 now I have multiplied by 2. So, I have to divide by 2 once again. Now, what is 2 times 1 1 point? The point will shift 1 place to the right right. So, it is 1 1 0 point this is in binary right plus this is 1.0 in decimal times 2 raise to minus 3 ok. Once again I will try to represent this in binary the integer part of it in binary. So, what is the integer part of it in binary it is just 1 right. So, this will become 1 point in binary plus 0 there is no other fractional part that is left. So, rather 0.0 in right and now once again I have a binary number I have another binary number there is a system binary addition. Let us not worry about that let us convert them to decimal add them up and put the sum back to binary. So, 1 1 0 is 6 1 is 1 6 plus 1 is 7 what is 7 in binary it is 1 1 1. So, this is 1 1 1 point in binary and there is no other fractional part now right. So, it is really 0 the fractional part is 0 into 2 raise to minus 3 is this clear. So, therefore, what have we done over we have said that 0.875 in decimal is 1 1 1 0 into 2 raise to minus 3 in binary. So, now we know what 2 raise to minus 3 does right this is basically dividing by 2 raise to 3 and what does division by 2 do it will just shift the binary point to the left. So, you have to shift the binary point 3 places to the left. So, this is 0.111 in binary here any morsel of doubt in anybody's mind how this happened there is nothing very deep we are doing here we have just converted the base from 10 to 2 rest is exactly the same ok. So, now let us try to find out what would be 9.875 right. So, this 0.875 we know is 0.111 9 is 1 0 0 1. So, this is basically 1 0 0 1 this is the 9 part and 0.111 is the 0.875 part right we want to write it as one single binary number which means we want to combine these two things, but note that these are being multiplied by 0 or positive powers of 2 these are being multiplied by negative powers of 2. So, even if I put these together with the binary point in between their multipliers will just stay the same right. So, if I just write 1 0 0 1 0.111 this part will get multiplied by powers of 2 exactly the same as this this part will get multiplied by powers of 2 exactly the same as this. So, therefore, this part will give me 9 this part will give me 0.875 and so, if I put them together remember in a binary representation what do we do we just take 1 into 2 raise to 3 plus 1 into 2 raise to 1 plus 1 into 2 raise to minus 1 plus 1 into 2 raise to minus 2. So, we add this part to this part right there is a plus when we go from binary to decimal. So, therefore, it is 9 plus 0.875 which is 9.875 right. So, 9.875 in binary is exactly this is that clear. Now, if you look at this number to the left of the radix point right this is the binary point in general arbitrary base it is called the radix point. So, to the left of the radix point there are 4 digits there are 4 bits rather a normalized mantissa requires that to the left of the radix point there is exactly 1 bit and that bit has to be 1 right. So, therefore, I have got to shift this over here how do I do that by dividing by 2 raise to 3, but then if I am dividing by 2 raise to 3 I have to also multiply by 2 raise to 3 right. So, 1001.111 since I want to push this here I have to divide this by 2 raise to 3 and I have to multiply it by 2 raise to 3 ok. So, this is 1.001111 times 2 raise to 3 clear this is 9.875 ok. Now, if you look at this mantissa this is in a normalized form to the left of the radix point there is exactly 1 bit and that is 1 ok. So, therefore, as we said that this is a redundant part because it is always in a normalized mantissa in binary to the left of the radix point if you require 1 bit and that has to be non-zero therefore, it is always got to be 1. So, it is always 1 point. So, we are not going to represent this right. So, the effective mantissa that will be represented is 001111 up to how many binary places like this is not decimal places now this is binary places. So, 1 2 3 4 5 6, but we require 23 places for the mantissa. So, you put whatever 17 zeros over here right repeated 17 times is that clear. So, therefore, the mantissa I mean once you look at this representation and you figure out that it is a normalized form then you can throw this out because there is no point of representing this right. So, the mantissa as it will be represented in the internal floating point representation will just be this remainder part after you throw out the 1 point right because the 1 point is kind of implicit in that representation this first 1 point is implicit is that clear you know 9.875 is as we have just seen 1.001111 into 2 raise to 3 this is the actual number, but in the floating point representation we will have a sign bit we will have the exponent bit we will have an implicit 1 point over here which will never be stored and this will be the mantissa right. So, this implicit 1 point is never stored because it is always 1 point. So, what is stored is for the sign I will have 0 because it is a positive number for the exponent I will have to once I get it in this normalized mantissa form I will have to find out what this exponent is represent it in signed 2s complement form. So, 3 in signed 2s complement form is 00000118 bits signed 2s complement. So, it has to start with because it is plus 3 the MSP has to be 0 and the rest of the bits have to just give me the magnitude of the number this signed 2s complement when it is positive we can just read off the magnitude straight away what about the mantissa there is an implicit 1 point which is already there which is never stored. So, I have just got to store the remainder of it right. So, it is 001111, but this requires 23 bits we have 6 bits over here. So, you put all of the 17 0s here is that clear to everybody ok good yes yeah. So, the exponent is 3 right I have to represent 3 using 8 bits because the exponent is 8 bits. So, ok. So, I have to represent 3 as a signed integer in 2s complement this is what we have to do right 3 is the exponent I have to represent it as a signed integer in 2s complement using 8 bits because the exponent has 8 bits right. So, how do we represent a signed integer in 2s complement using 8 bits we first see what the sign is that tells us what the MSB is ok. Now, if the MSB is 0 there is nothing to be done for the other things we can just write off the magnitude straight away remember that circle we drew the other day. So, on this side we had 00001, 010, 011 and this we said is plus 0, plus 1, plus 2, plus 3 the 0 was telling us that it is plus and the rest of the bits were just telling us what that number is right. So, for positive numbers in signed 2s complement representation just put a 0 for the sign just write the magnitude of the number as is. So, here I have to write using the remaining 7 bits 3. So, which is 5 0s and 1 1 if it was a negative number if it was minus 3 suppose the exponent was minus 3 in another problem. So, now minus 3 in signed as a signed integer in 2s complement using 8 bits right. So, because it is minus the MSB is going to be 1 and because it is 1 we now know that it is in this part of the circle and it is in this part of the circle that you have to do all of that jugglery to figure out what the magnitude is. The other part of the positive part of the circle that is it is very straightforward just read off the magnitude fine. So, now if I have to do it as minus 3 then how should it happen I will have to write something here such that when the bits are flipped and I add 1 to it I get the magnitude. So, before adding 1 I should have 2 and then by flipping the bits I should have gotten 2 which means the number that I should get is the flipped version of 2. So, what is 2 in 7 bits 2 in 7 bits is this. So, you have to flip this so it will be 1 1 1 1 1 0 1 is that fine. So, when you are writing a signed integer if it is a positive integer that is the easy part just put a 0 for the MSB just write the magnitude straight away as an unsigned integer. If it is negative that is the more complicated part because then you are in this part of the circle and this we saw was you know we have to go like this and so this must represent minus 4 this must represent minus 3 and so on. But in this part of the circle there is absolutely no problem this is exactly as we would like to have it right. So, it is only when it is negative you put the MSB as 1 and then you do the rest of the jugglery with the remainder bits right you take the magnitude subtract 1 find its binary and then flip the bits is that clear ok good. So, we will also convert these into some kind of lecture notes and put it up on the website so that yeah 9.875 into 10 raise to minus 7. So, let me ask you if it was not 10 raise to minus 7 suppose I give you the following number let us say 4.321 into 5 raise to minus 3 or actually 5 raise to minus 7 and I asked you to write with the base 10 over here how would you do it really. So, suppose this is minus 70 so I mean since all of you have come through JEE and you know the MSC students have also completed a bachelor's course so is it very hard to see that minus 5 raise to whatever you give me is also 2 raise to something I mean all of you know how to do this right just take logarithms do that. So, similarly 10 raise to minus 7 can be converted to 2 raise to something so just write out what the 2 raise to something is and then the rest of it is the same I mean I would do the same thing here if I asked you to represent it as a power of 10 I cannot go on finding out 5 raise to 70 and then divide that number it is not going to work. So, I mean it is going to work in principle it is not going to work in practice. So, you just convert it to 2 raise to so does everybody know how to get this thing yes so 5 raise you take log on both sides so let us call this x over here right take log base 2 on both sides so minus 70 times log 5 base 2 is x right log base 2 of 2 raise to x is x. So, the thing that you should put up here is 3 times log 5 base 2 right. So, log 5 base 2 would be available somewhere you know these are pre computed things just multiply that you get the number and so you have basically converted your you have shifted your base right. You know of course, you know if log 5 base 2 cannot be expressed within the number of bits or number of digits of precision you have you will have some imprecision, but then that is kind of inherent when you are trying to shift bases. So, does that answer your question I have not answered your question, but I hope I have told you how to answer your question I think it was 2 raise to minus 32 yeah because in fact, we the just prior to that we represented minus 32 as a signed 8 bit representation. So, that exponent should come directly there. So, it was 2, but even if it was 10 raise to minus 32 you know how to do it now right good fine. So, we can ask you quiz questions about floating point representations right ok good.