1 00:00:20,310 --> 00:00:23,680 In this video will be talking about the floating point 2 00:00:23,680 --> 00:00:27,050 notation, which is designed to address the problem that we 3 00:00:27,050 --> 00:00:30,757 talked about in one of the previous videos, where we noted 4 00:00:30,757 --> 00:00:34,801 that the radix point was jumping around and I mentioned that it 5 00:00:34,801 --> 00:00:38,508 can cause a bit of a confusion for the computer. Throughout 6 00:00:38,508 --> 00:00:42,552 this video I will be talking about the 8 bit floating point 7 00:00:42,552 --> 00:00:46,596 notation which you will find out very soon. It's a really small 8 00:00:46,596 --> 00:00:50,303 system, so it doesn't allow you to work with huge numbers. 9 00:00:50,330 --> 00:00:55,159 However, it's convenient enough to understand and work with on a 10 00:00:55,159 --> 00:00:59,988 paper, and you can just extend the general rules to any 11 00:00:59,988 --> 00:01:04,378 systems. So let's see what is this floating point notation 12 00:01:04,378 --> 00:01:09,207 looks like. Well, the floating point notation is, 8 bits are 13 00:01:09,207 --> 00:01:14,475 broken up into three parts. The first part is just one single 14 00:01:14,475 --> 00:01:20,182 digits telling you what is the sign of your number. The next 3 15 00:01:20,182 --> 00:01:25,089 digits. We called the exponent, which will tell the computer 16 00:01:25,089 --> 00:01:30,981 where to move the decimal point from here and the last four 17 00:01:30,981 --> 00:01:36,052 digits. Called the mantissa. Now the mantissa is the normalized 18 00:01:36,052 --> 00:01:40,032 version of your binary number into the 0.122 format. We're 19 00:01:40,032 --> 00:01:44,808 going to go through it in in details. Now. The exponent bit 20 00:01:44,808 --> 00:01:49,982 in this format is just three bits, so you can only move your 21 00:01:49,982 --> 00:01:55,156 decimal point to three in to the right or to the left, which 22 00:01:55,156 --> 00:01:59,932 straight away as it as you that you can't really cover great 23 00:01:59,932 --> 00:02:01,922 ranges, but it's good enough. 24 00:02:02,760 --> 00:02:07,105 And the exponent is expressed as a 3 bits 2's complement 25 00:02:07,105 --> 00:02:13,752 notation. So the sign bit if we have a positive number be 26 00:02:13,752 --> 00:02:20,148 going to use zero if we have a negative number, we're going to 27 00:02:20,148 --> 00:02:26,052 use one. As I said, the exponent is 3 bits 2's complement. 28 00:02:27,060 --> 00:02:33,561 And the mantissa, which is always 4 bits in this particular 29 00:02:33,561 --> 00:02:37,107 number, we're going to have it 30 00:02:37,107 --> 00:02:44,101 normalized. So when you have got a negative 31 00:02:44,101 --> 00:02:49,099 number, something like minus 3 1/2. 32 00:02:50,860 --> 00:02:55,624 How are you going to convert this into an 8 bit floating 33 00:02:55,624 --> 00:02:57,609 point notation while step one 34 00:02:57,609 --> 00:02:58,403 will be? 35 00:02:59,410 --> 00:03:04,538 Identify. The sign bit. 36 00:03:06,510 --> 00:03:12,321 That this is going to be the easiest one for negative #0 for 37 00:03:12,321 --> 00:03:16,791 positive number. Step two will be is convert into binary. 38 00:03:20,660 --> 00:03:23,260 And normalize 39 00:03:25,040 --> 00:03:27,364 To get to them on this so. 40 00:03:28,750 --> 00:03:32,045 Step 41 00:03:32,045 --> 00:03:38,940 3. Is find the exponent. 42 00:03:39,610 --> 00:03:45,180 Which will be something to do with the month. So 43 00:03:45,180 --> 00:03:49,636 how you normalize your number and express it. 44 00:03:52,120 --> 00:03:53,869 As three bits. 45 00:03:55,460 --> 00:03:59,415 These complement notation and the last step. 46 00:03:59,970 --> 00:04:04,227 Is just to pull everything together and put it into the 47 00:04:04,227 --> 00:04:08,871 format of the sign followed by three of the exponent digits and 48 00:04:08,871 --> 00:04:10,806 followed by four of the 49 00:04:10,806 --> 00:04:15,260 mantissa. OK, it sounds quite a long and probably a little bit 50 00:04:15,260 --> 00:04:19,740 alien in theory, but I think what we are going to help us if 51 00:04:19,740 --> 00:04:21,980 we go through a couple of simple 52 00:04:21,980 --> 00:04:25,095 examples. So let's look at minus 53 00:04:25,095 --> 00:04:27,029 one. And a quarter. 54 00:04:27,670 --> 00:04:31,900 OK sign bit going to be one because this 55 00:04:31,900 --> 00:04:33,780 is a negative number. 56 00:04:36,040 --> 00:04:41,200 Not we're going to find the mantissa for that first. What we 57 00:04:41,200 --> 00:04:45,930 need to do? We need to convert 1 1/4 into binary. 58 00:04:47,660 --> 00:04:51,170 So. Let's again bring 59 00:04:51,170 --> 00:04:57,870 in the. Place values Now this is the radix point. Here is 124 and 60 00:04:57,870 --> 00:05:02,790 the rest of them. The whole numbers and after comes up half 61 00:05:02,790 --> 00:05:07,710 a quarter on 8 etc etc. Now I've chosen deliberately choosing a 62 00:05:07,710 --> 00:05:14,270 simple example so to write 1 1/4 in binary or we need to do is 1. 63 00:05:14,870 --> 00:05:19,814 Radix Point followed with 01. So this is our binary number, but 64 00:05:19,814 --> 00:05:22,698 we need to normalize it into the 65 00:05:22,698 --> 00:05:26,903 mantissa. So the normalized the normalized monthly start 66 00:05:26,903 --> 00:05:30,674 then will be 0.101. And remember the amount Esther 67 00:05:30,674 --> 00:05:36,959 needs to be 4 bits, so I need to put an extra 0 into here. 68 00:05:36,959 --> 00:05:41,568 Now what happens in this case? Now I found my mantissa. 69 00:05:43,020 --> 00:05:47,700 I found mine on Monday so now, but I still need my exponent. 70 00:05:48,390 --> 00:05:53,174 The exponent the easier way to think about it is to try to 71 00:05:53,174 --> 00:05:56,854 think about the exponent from the computer's point of view, 72 00:05:56,854 --> 00:05:58,694 because once the computer read 73 00:05:58,694 --> 00:06:03,340 the. Sign me and the exponent wait, then the computer will 74 00:06:03,340 --> 00:06:08,215 know where to start from and how many places to move that Radix 75 00:06:08,215 --> 00:06:12,715 point. Now from this radix point here in them from the mantissa 76 00:06:12,715 --> 00:06:16,840 to get back to the original number which remember was minus 77 00:06:16,840 --> 00:06:21,340 one and a quarter to get back to the original number. The 78 00:06:21,340 --> 00:06:25,465 computer will need to move one places into this direction and 79 00:06:25,465 --> 00:06:29,590 this is the positive direction. So I'm moving one place too. 80 00:06:29,620 --> 00:06:34,050 The right that's a positive. It's like multiplying by 10 81 00:06:34,050 --> 00:06:38,037 in normal numbers in normal circumstances, so I'm moving 82 00:06:38,037 --> 00:06:42,024 the decimal point by one places into the positive 83 00:06:42,024 --> 00:06:43,796 direction, so my exponent. 84 00:06:45,700 --> 00:06:50,991 Will be positive one, but what does positive one look like in 3 85 00:06:50,991 --> 00:06:52,212 bits? This compliment? 86 00:06:52,720 --> 00:06:57,676 So remember I've only got 3 bits. It's a positive number, so 87 00:06:57,676 --> 00:07:03,458 the 1st digit will be 0 and it's just positive one, so it's 001. 88 00:07:04,010 --> 00:07:09,796 So pulling all these things together and putting it into the 89 00:07:09,796 --> 00:07:11,374 sign, exponent, exponent, 90 00:07:11,374 --> 00:07:16,508 mantissa. Format the sign negative number will be one. The 91 00:07:16,508 --> 00:07:22,124 exponent is positive one, so it will be 001 and the months are 92 00:07:22,124 --> 00:07:26,876 now because the computer knows that the mantissa is designed to 93 00:07:26,876 --> 00:07:31,196 be zero point something something so that zero point. We 94 00:07:31,196 --> 00:07:36,380 can always forget and I can just write down the following 4 95 00:07:36,380 --> 00:07:41,132 digits 1010. So this is equivalent to minus 1 1/4. So 96 00:07:41,132 --> 00:07:43,292 this is the 8 bit. 97 00:07:43,310 --> 00:07:46,094 Floating point notation 4 -- 1 98 00:07:46,094 --> 00:07:51,742 1/4. Now you might spot here what happens if I had to put. 99 00:07:51,742 --> 00:07:56,435 Let's see after normalization, I end up with five 6 or 7 digits. 100 00:07:56,435 --> 00:08:01,128 Well with this Ed bits floating point, we would have to cut off 101 00:08:01,128 --> 00:08:05,460 at the first 4 bits, so we would have trunking error. Obviously 102 00:08:05,460 --> 00:08:09,070 the computer works with bigger length of digits, therefore that 103 00:08:09,070 --> 00:08:12,680 trunking error doesn't come up as much. So in practical 104 00:08:12,680 --> 00:08:16,290 situation when you have to carry out the calculations, trunking 105 00:08:16,290 --> 00:08:17,373 errors do occur. 106 00:08:17,420 --> 00:08:21,100 In real situations, when the computer does it, it's very 107 00:08:21,100 --> 00:08:21,836 very minimized. 108 00:08:23,060 --> 00:08:25,030 Let's look at another example. 109 00:08:26,300 --> 00:08:30,240 Minus two and two 8. 110 00:08:31,420 --> 00:08:33,394 Now when I look at this number. 111 00:08:34,540 --> 00:08:38,908 Well, I can see here straight away that I can cancel this one 112 00:08:38,908 --> 00:08:42,268 down, and this is actually minus two end of quarter. 113 00:08:43,040 --> 00:08:45,620 OK, so step one. 114 00:08:46,500 --> 00:08:52,548 Sign and in this case the sign will be equal to 1 because I'm 115 00:08:52,548 --> 00:08:54,708 talking about a negative number. 116 00:08:54,840 --> 00:08:58,866 Step 2 117 00:08:58,866 --> 00:09:00,879 convert. 118 00:09:02,540 --> 00:09:04,520 And find the mantissa. 119 00:09:05,600 --> 00:09:12,542 So 2 1/4. Let's convert that 120 00:09:12,542 --> 00:09:19,066 into binary. Ring in the place values again, this is 121 00:09:19,066 --> 00:09:25,534 your radix .124 half or quarter and an 8. So for two to build 122 00:09:25,534 --> 00:09:32,464 up the whole part we need 1 zero and the radix point for 1/4. We 123 00:09:32,464 --> 00:09:38,470 don't need any half and we use 1/4 so this is our ordinary 124 00:09:38,470 --> 00:09:44,476 binary which is equal to 2 1/4. But remember now we need to 125 00:09:44,476 --> 00:09:49,036 normalize it. And the normalization process goes as. 126 00:09:49,990 --> 00:09:53,206 Bring it into the zero point. 127 00:09:53,930 --> 00:09:57,531 One and the rest of the digit would follow, so if I normalize 128 00:09:57,531 --> 00:10:00,855 it, what would means I would need to move this decimal point 129 00:10:00,855 --> 00:10:02,794 into the front in here, so I 130 00:10:02,794 --> 00:10:06,140 would have. The point moved into 131 00:10:06,140 --> 00:10:12,735 here. And then what would follow 132 00:10:12,735 --> 00:10:15,888 now is 0.1001. 133 00:10:16,290 --> 00:10:20,346 OK, and remember that this part will be our mantissa, the one 134 00:10:20,346 --> 00:10:22,036 that follows after the point. 135 00:10:23,250 --> 00:10:30,498 Then step three is we need to identify 136 00:10:30,498 --> 00:10:33,922 or. Express the 137 00:10:33,922 --> 00:10:38,847 exponent. Now remember the easiest way to think about the 138 00:10:38,847 --> 00:10:43,170 exponent is how many places you would need to move the 139 00:10:43,170 --> 00:10:47,493 decimal point. If you were the computer. So you were reading 140 00:10:47,493 --> 00:10:51,816 this number and the origonal number was one 0.01, so you 141 00:10:51,816 --> 00:10:56,532 need to tell the computer via the exponent that he needs to 142 00:10:56,532 --> 00:11:01,248 get to this number from this number. So what would you need 143 00:11:01,248 --> 00:11:05,964 to do in here? You would need to move the decimal point. 144 00:11:07,070 --> 00:11:11,640 Two places into this direction, and this is the positive 145 00:11:11,640 --> 00:11:17,124 direction, so the exponent would have to be positive too, and the 146 00:11:17,124 --> 00:11:21,237 positive two in three bits 2's complement. Remember positive 147 00:11:21,237 --> 00:11:27,178 number is zero and two is 1 zero, so this is our exponent 148 00:11:27,178 --> 00:11:32,662 now. And Lastly, pull all these bits together. The sign bit was 149 00:11:32,662 --> 00:11:39,945 one. The three bits of the exponent is 010, and the four 150 00:11:39,945 --> 00:11:42,205 bits of the mantissa. 151 00:11:42,210 --> 00:11:48,447 Is 1001, which is this bit here. 152 00:11:49,190 --> 00:11:55,352 So this is equal to minus 153 00:11:55,352 --> 00:11:59,460 two and two eighths. 154 00:12:00,980 --> 00:12:08,000 Now look at the last example and the locks. That last example 155 00:12:08,000 --> 00:12:15,020 will be minus 116th sign bit which is. First step is again 156 00:12:15,020 --> 00:12:19,700 one because it's a negative number, Step 2. 157 00:12:20,290 --> 00:12:23,060 Now I need to convert. 158 00:12:24,090 --> 00:12:26,850 And find the mantissa. 159 00:12:29,390 --> 00:12:35,198 So place values. I don't have any whole numbers, so all I'm 160 00:12:35,198 --> 00:12:40,038 going to do, I'm going to express the fractional place 161 00:12:40,038 --> 00:12:42,942 values or half a quarter on 162 00:12:42,942 --> 00:12:49,485 AIDS. And the 16 and again because of the way 163 00:12:49,485 --> 00:12:54,405 I've chosen this number, this will be 0.0001. 164 00:12:55,680 --> 00:13:01,389 OK that remember that your monthly site has to be 0.1 165 00:13:01,389 --> 00:13:07,617 something. So how can I get from this number into this format 166 00:13:07,617 --> 00:13:14,883 now? The only way I can get to here is by moving the decimal 167 00:13:14,883 --> 00:13:16,440 .123 places so. 168 00:13:17,440 --> 00:13:21,864 The exponent, which is our Step 3. 169 00:13:24,540 --> 00:13:28,140 I moved my decimal .3 places. 170 00:13:28,640 --> 00:13:31,780 But have I moved it into positive or negative direction? 171 00:13:31,780 --> 00:13:35,548 Let's look at that again. So a normalized it. But remember that 172 00:13:35,548 --> 00:13:39,630 mantis and needs to be 4 bits long, so I need to put. 173 00:13:41,230 --> 00:13:45,250 Three more zeros in here and now. The computer comes in and 174 00:13:45,250 --> 00:13:49,270 you telling the computer that from this number you want to go 175 00:13:49,270 --> 00:13:50,945 back to the original number. 176 00:13:51,620 --> 00:13:56,014 OK, so from here to get back to the origin number of 0.3 177 00:13:56,014 --> 00:14:00,070 zeros followed by the one you have to tell the computer to 178 00:14:00,070 --> 00:14:01,422 move the radix point. 179 00:14:02,850 --> 00:14:08,878 Into the opposite direction done before, so this exponent will be 180 00:14:08,878 --> 00:14:15,973 negative 3. Now let's see if we can express negative 3IN. 181 00:14:16,670 --> 00:14:18,530 3 bits, two complements. 182 00:14:19,820 --> 00:14:25,309 Remember how we did that is compliment. If it comes to 183 00:14:25,309 --> 00:14:30,798 negative numbers, just Express 3 as a 3 bit binary number, 184 00:14:30,798 --> 00:14:35,289 positive three and positive three again using the place 185 00:14:35,289 --> 00:14:40,279 values is 124. Remember, we don't have anything else in 186 00:14:40,279 --> 00:14:46,394 here. So it's 011 and to make it into negative three you need 187 00:14:46,394 --> 00:14:51,620 to copy the digits until you copy the one which is in our 188 00:14:51,620 --> 00:14:56,444 case is the very first step and then invert everything else swap 189 00:14:56,444 --> 00:15:01,670 once for zeros and zeros for once for 01. So this is your 190 00:15:01,670 --> 00:15:03,278 negative three in here. 191 00:15:03,790 --> 00:15:05,710 So your exponent. 192 00:15:07,690 --> 00:15:11,320 He is 101. 193 00:15:11,990 --> 00:15:17,210 Put the whole thing together. Sign bit was one, 194 00:15:17,210 --> 00:15:22,430 the exponent is 101 and a month is soft. 195 00:15:24,280 --> 00:15:31,573 Is 1 followed by 3 zero, so this is the equivalent of minus 196 00:15:31,573 --> 00:15:33,256 1 / 16. 197 00:15:35,140 --> 00:15:38,803 Not just to recap, with the computer would actually do in 198 00:15:38,803 --> 00:15:42,799 here. The computer would come and start to read the digits OK 199 00:15:42,799 --> 00:15:46,129 with this digit. Here you telling the computer that he 200 00:15:46,129 --> 00:15:49,792 needs to think about a negative number. With this digit you 201 00:15:49,792 --> 00:15:53,122 telling the computer how many places in what direction he 202 00:15:53,122 --> 00:15:57,118 needs to move the radix point that starts from here and then. 203 00:15:57,118 --> 00:16:01,447 That way it will be able to re normalize the mantissa. Find out 204 00:16:01,447 --> 00:16:03,112 what number hides behind this 205 00:16:03,112 --> 00:16:09,040 binary code. I hope you not have a clear idea of how to convert 206 00:16:09,040 --> 00:16:12,540 numbers into 8 bits floating point notation on the following 207 00:16:12,540 --> 00:16:15,690 pages you will have some properties questions and then 208 00:16:15,690 --> 00:16:17,790 you will find the answers to 209 00:16:17,790 --> 00:16:21,080 these. So these are the practice questions. 210 00:16:27,060 --> 00:16:28,760 And here are the answers.