1 00:00:17,800 --> 00:00:22,246 In this video I'm going to show you a different way of using 2 00:00:22,246 --> 00:00:25,324 this complement notation pending on which method makes more 3 00:00:25,324 --> 00:00:29,086 sense. Which method is easier for you? You've got the choice. 4 00:00:29,086 --> 00:00:33,190 Doesn't matter which method you use, so just to recap why we're 5 00:00:33,190 --> 00:00:36,952 doing the twos complement notation that this is one way to 6 00:00:36,952 --> 00:00:40,030 represent negative numbers in the binary number system. And 7 00:00:40,030 --> 00:00:44,476 again to recap, if the number starts with a zero in the twos 8 00:00:44,476 --> 00:00:48,238 complement notation that we know that this is a positive number. 9 00:00:48,340 --> 00:00:54,206 And if a number starts with N1, we know that this is a negative 10 00:00:54,206 --> 00:00:59,234 number, so the 1st digit in the twos complement notation is used 11 00:00:59,234 --> 00:01:03,005 for the sign bit. Therefore there's a limitation. So 12 00:01:03,005 --> 00:01:07,195 depending on how many bits you using for this compliment 13 00:01:07,195 --> 00:01:12,223 notation, we can only use one less bit for building the actual 14 00:01:12,223 --> 00:01:16,832 numbers. So again, just to recap, in case you haven't seen 15 00:01:16,832 --> 00:01:18,927 the previous video, every single 16 00:01:18,927 --> 00:01:23,386 number. In the two complement notation have to be used at a 17 00:01:23,386 --> 00:01:27,302 fixed length, so you can't talk about, just generally the twos 18 00:01:27,302 --> 00:01:31,218 complement notation. You always have to say what length of bits 19 00:01:31,218 --> 00:01:35,490 you talking about, so you can talk about the four bits twos 20 00:01:35,490 --> 00:01:39,406 compliment. You can talk about the 7 bits this compliment, or 21 00:01:39,406 --> 00:01:43,678 you can talk about the 22 bits 2's complement, but you always 22 00:01:43,678 --> 00:01:47,238 have to give whoever reads numbers the length, the fixed 23 00:01:47,238 --> 00:01:50,442 length of the numbers. Otherwise the deuce complement notation. 24 00:01:50,830 --> 00:01:54,400 It doesn't necessarily work, so this second method is slightly 25 00:01:54,400 --> 00:01:58,327 different from the previous one, but the answers will be the 26 00:01:58,327 --> 00:02:02,968 same. So in the previous method, we converted and then we kind of 27 00:02:02,968 --> 00:02:06,181 inversion process. In this method we also using something 28 00:02:06,181 --> 00:02:07,609 similar, so step one. 29 00:02:08,630 --> 00:02:10,766 Again, we will be to convert. 30 00:02:12,100 --> 00:02:13,160 Into binary. 31 00:02:15,400 --> 00:02:17,408 But then Step 2. 32 00:02:18,630 --> 00:02:21,486 Would be just a simple inversion. 33 00:02:22,800 --> 00:02:26,320 So we don't have to do anything like copying bits 34 00:02:26,320 --> 00:02:30,192 or whatever. We just invert all of the digits, but then 35 00:02:30,192 --> 00:02:31,600 comes on next tab. 36 00:02:32,830 --> 00:02:35,250 And that is odd. 37 00:02:36,390 --> 00:02:36,960 1. 38 00:02:38,080 --> 00:02:41,044 And I'm going to show you why this is working and how 39 00:02:41,044 --> 00:02:43,761 we can do this, but let's look at an exact example. 40 00:02:45,230 --> 00:02:52,202 So what would be negative four in four Bits 2's complement? OK, 41 00:02:52,202 --> 00:02:53,945 so step one. 42 00:02:57,090 --> 00:03:00,660 Convert so again, we're using 4 43 00:03:00,660 --> 00:03:01,255 bits. 44 00:03:01,940 --> 00:03:07,976 1248 and four is just 45 00:03:07,976 --> 00:03:11,539 100. And don't forget we need the 46 00:03:11,539 --> 00:03:13,066 zero first here. 47 00:03:14,300 --> 00:03:14,920 OK. 48 00:03:16,390 --> 00:03:19,588 Then Step 2 is the invert. 49 00:03:22,090 --> 00:03:26,338 So what happens here then everywhere I have got a zero, I 50 00:03:26,338 --> 00:03:30,940 turn it into your one and everywhere when I have a one, I 51 00:03:30,940 --> 00:03:35,896 turn it into a 0 so zero become one and one becomes zero. And 52 00:03:35,896 --> 00:03:37,666 then comes the extra step. 53 00:03:39,140 --> 00:03:41,990 Is the adding one so one? 54 00:03:44,990 --> 00:03:47,070 1 + 1 makes 0. 55 00:03:47,760 --> 00:03:54,956 Carry the one 1 + 1 makes 0 carry the one 1 + 0 56 00:03:54,956 --> 00:04:00,096 makes one and one plus nothing keeps one, so minus 57 00:04:00,096 --> 00:04:05,750 four is the same as 1100 in 4 bits 2's complement. 58 00:04:07,490 --> 00:04:13,406 So let's look at minus six and again converted using the four 59 00:04:13,406 --> 00:04:16,364 bits to complement, so step one 60 00:04:16,364 --> 00:04:22,227 convert. So 4 bits on using 1, two for an 8 and I know 61 00:04:22,227 --> 00:04:26,655 that the six I will the negative six. I will be able 62 00:04:26,655 --> 00:04:31,452 to show because it's less than 8, so six is 4 + 2. 63 00:04:33,200 --> 00:04:37,243 And again I need the rest of the zeros and I need to 64 00:04:37,243 --> 00:04:40,664 0 here as well because I'm talking about four bits 2's 65 00:04:40,664 --> 00:04:41,908 complement, then Step 2. 66 00:04:43,210 --> 00:04:43,950 Invert. 67 00:04:45,700 --> 00:04:49,196 So zeros becomes ones and ones become zero. 68 00:04:50,860 --> 00:04:52,400 And then the last step. 69 00:04:54,340 --> 00:05:01,242 Is plus one so one comes here and I just need to add them 70 00:05:01,242 --> 00:05:08,637 together. 1 + 1 makes 0 karida one 1 + 0 makes 1 zero plus 71 00:05:08,637 --> 00:05:16,032 nothing is 01 plus nothing is 1, so minus six is the same as 1010 72 00:05:16,032 --> 00:05:21,948 in 4 bits. This compliment now don't forget that this is not 73 00:05:21,948 --> 00:05:23,920 the same as 1010. 74 00:05:23,980 --> 00:05:28,216 Just as an ordinary binary number. So if you just look at 75 00:05:28,216 --> 00:05:32,452 this from context, it needs to be cleared. If it's a compliment 76 00:05:32,452 --> 00:05:35,276 notation, or if it's just ordinary binary notation, 77 00:05:35,276 --> 00:05:37,747 because depending on the difference between complements 78 00:05:37,747 --> 00:05:41,630 and ordinary numbers when you trying to convert it back into 79 00:05:41,630 --> 00:05:44,807 to find out the decimal equivalent, you would do 80 00:05:44,807 --> 00:05:45,866 different process is. 81 00:05:47,750 --> 00:05:53,301 Let's look at another example. So what is 7 in five Bits 2's 82 00:05:53,301 --> 00:05:57,998 complement notation? So 75 bits 2's complement. Now this is a 83 00:05:57,998 --> 00:06:03,122 positive number, so when it's a positive number I don't need to 84 00:06:03,122 --> 00:06:07,392 do the inversion process. So again, just like in the 85 00:06:07,392 --> 00:06:10,808 previous video, positive numbers are the easy examples 86 00:06:10,808 --> 00:06:15,932 because all we need to do is just step one the conversion. 87 00:06:19,090 --> 00:06:23,757 So the place values again, we're using that 5 bits, so make sure 88 00:06:23,757 --> 00:06:28,424 that you using order 5 bits 124, eight, 16 that's all 12345 bits. 89 00:06:28,424 --> 00:06:34,168 Then, which one of these do we need to be at? 7 again? 7 is 1 90 00:06:34,168 --> 00:06:39,194 less than 8, so I will need to use every single digits that are 91 00:06:39,194 --> 00:06:44,938 less than 8. So 1 + 2 + 4 makes 7 altogether, but because it's 5 92 00:06:44,938 --> 00:06:49,246 minutes to complement notation, I need to put the zeros in front 93 00:06:49,246 --> 00:06:56,786 of it. So positive 7 is the same as 00111 in five bits, 94 00:06:56,786 --> 00:06:58,604 this complement notation. 95 00:07:02,160 --> 00:07:07,942 Now how can we do it the other way around? So let's say that 96 00:07:07,942 --> 00:07:14,137 you are given a number 10011 and you are told that this is a 5 97 00:07:14,137 --> 00:07:15,789 bits 2's complement notation 98 00:07:15,789 --> 00:07:20,396 number. So how can we find out what number is this one 99 00:07:20,396 --> 00:07:23,456 now? Remember that we went from when we went from 100 00:07:23,456 --> 00:07:25,904 decimal to binary, viewed under conversion. Then we 101 00:07:25,904 --> 00:07:29,576 done the inversion and then we done the odd one. So when 102 00:07:29,576 --> 00:07:32,636 you've got the binary equivalent and you want to go 103 00:07:32,636 --> 00:07:36,614 back to the decimal, then you have to do that step by step 104 00:07:36,614 --> 00:07:39,368 going backwards. So the Step 1 first here be. 105 00:07:40,770 --> 00:07:47,192 Take away one. Let's do that now. So 10011 I need to take 106 00:07:47,192 --> 00:07:50,918 away one. One takeaway one is 107 00:07:50,918 --> 00:07:56,110 0. One takeaway, nothing is 1 zero takeaway. Nothing is 00 108 00:07:56,110 --> 00:08:00,213 takeaway, nothing is zero and one takeaway zero is 1 so 109 00:08:00,213 --> 00:08:04,316 that is the first stage. Then remember that the middle step 110 00:08:04,316 --> 00:08:04,689 was. 111 00:08:06,860 --> 00:08:12,404 The inversion, So what I need to do now I need to invert this 112 00:08:12,404 --> 00:08:16,364 number so zero becomes 11, becomes 00, becomes 10, becomes 113 00:08:16,364 --> 00:08:20,720 one and one becomes zero, and this is the ordinary binary 114 00:08:20,720 --> 00:08:25,868 equivalent of this 5 bits 2's complement an. Now what I can do 115 00:08:25,868 --> 00:08:27,848 is do the last step. 116 00:08:29,140 --> 00:08:32,684 Which in this case will be the conversion. 117 00:08:34,010 --> 00:08:36,936 So just put the place values on top of the number. 118 00:08:38,450 --> 00:08:40,100 8 + 4 + 1. 119 00:08:42,280 --> 00:08:47,012 That makes 13, so this number is the equivalent is minus 13 OK 120 00:08:47,012 --> 00:08:51,380 and we have done this conversion in the previous video, so you 121 00:08:51,380 --> 00:08:55,384 can double check there and convince yourself that this is a 122 00:08:55,384 --> 00:08:57,204 correct way of doing it. 123 00:09:00,250 --> 00:09:07,666 So look at one more example 01011. This is again A5 bits. 124 00:09:08,810 --> 00:09:10,688 Two's complement notation. 125 00:09:12,270 --> 00:09:16,076 Now again, this is a positive number because it starts with 126 00:09:16,076 --> 00:09:19,536 zero, so therefore this number has not gone through the 127 00:09:19,536 --> 00:09:23,342 inversion, and adding one process. So when I see a number 128 00:09:23,342 --> 00:09:27,494 like this, I know it's going to be an easy calculation because 129 00:09:27,494 --> 00:09:32,338 all I need to do is just one step and that is the conversion. 130 00:09:35,010 --> 00:09:37,770 So how do I convert this number back to ordinary 131 00:09:37,770 --> 00:09:40,254 binary? Let's just copy this one down here again. 132 00:09:41,860 --> 00:09:46,332 And the easiest and quickest way, at least for me, is to put 133 00:09:46,332 --> 00:09:48,052 the place values on top. 134 00:09:49,860 --> 00:09:55,710 And then just add those numbers together. So 8 + 2 + 1 makes 11, 135 00:09:55,710 --> 00:09:58,050 so this number is positive 11. 136 00:10:01,730 --> 00:10:06,284 So let's look at a couple of eight bits to complement 137 00:10:06,284 --> 00:10:10,838 examples because that is quite widely used. So how could we 138 00:10:10,838 --> 00:10:16,268 represent minus? 94 in eight Bits 2's complement. 139 00:10:17,230 --> 00:10:21,910 So remember step one good. It's a negative number. I need to go 140 00:10:21,910 --> 00:10:25,150 through all three steps. Step one will be conversion. 141 00:10:27,230 --> 00:10:33,678 So 8 bits 124 eight 1630 two 64128, 142 00:10:33,678 --> 00:10:40,126 so 12345678 different bits to represent my number. 143 00:10:40,126 --> 00:10:46,574 So I need to build up 94 so. 144 00:10:47,380 --> 00:10:52,744 64 I'm going to use and the difference between 94 and 64. 145 00:10:53,500 --> 00:10:58,345 It's a handy 30, so the next step is how can I build up 30 146 00:10:58,345 --> 00:11:02,867 from the rest of the digits? Now 32 is too big because I'm only 147 00:11:02,867 --> 00:11:07,066 need 30, so the next biggest place where you can use is 16, 148 00:11:07,066 --> 00:11:10,942 so it takes 16 away from this and the remainder is 14. 149 00:11:12,520 --> 00:11:14,746 I can take eight from the 14. 150 00:11:16,180 --> 00:11:21,108 The remainder is 6 and six is 4 + 2 even number, so I'm 151 00:11:21,108 --> 00:11:26,036 expecting the last bit to be 0 and it is because I'm not using 152 00:11:26,036 --> 00:11:30,260 the one and again, don't forget that you always need to make 153 00:11:30,260 --> 00:11:34,132 sure that if there are empty spaces before your number, you 154 00:11:34,132 --> 00:11:38,708 need to fill that in with zeros to make sure that your number 155 00:11:38,708 --> 00:11:43,988 is 8 bits long. OK, so that was first step, the Step 2 then was 156 00:11:43,988 --> 00:11:44,692 the inversion. 157 00:11:45,880 --> 00:11:50,404 So what we need to do now, invert every single bits to the 158 00:11:50,404 --> 00:11:53,188 opposite, so zero become one, one becomes 0. 159 00:11:57,230 --> 00:12:01,050 So zero becomes 11, becomes zero and zero become one. 160 00:12:01,050 --> 00:12:04,488 This is the inverted number. But what happens now? 161 00:12:06,620 --> 00:12:11,708 Is I need to add 1. OK, so let's just copy the 162 00:12:11,708 --> 00:12:13,404 number down here again. 163 00:12:17,030 --> 00:12:18,720 An other one to it. 164 00:12:20,450 --> 00:12:25,370 1 + 1 is zero karida one 1 + 0 is 1. 165 00:12:25,980 --> 00:12:29,159 And from here on I don't need to add anything, so 166 00:12:29,159 --> 00:12:30,604 I can just copy them. 167 00:12:37,750 --> 00:12:41,699 So the edmister is binary equivalent of minus 94. Is this 168 00:12:41,699 --> 00:12:45,289 number now? You might ask yourself a question that you 169 00:12:45,289 --> 00:12:48,879 know when I'm adding binary numbers together, sometimes I do 170 00:12:48,879 --> 00:12:53,187 have to do loads of carrying. And what happens if I carried 171 00:12:53,187 --> 00:12:57,854 this number over? So what happens if I needed to add 1 to 172 00:12:57,854 --> 00:13:00,726 it and then I need to carry it? 173 00:13:00,726 --> 00:13:04,440 Well, that. Extra bit here would be called the overflow. 174 00:13:07,510 --> 00:13:10,762 And what the computer does is just simply ignores it. So if 175 00:13:10,762 --> 00:13:14,285 after the addition you end up with a 9 bits long number, all 176 00:13:14,285 --> 00:13:17,808 you need to do is ignore the first bit and your answer will 177 00:13:17,808 --> 00:13:19,163 be just that 8 bit. 178 00:13:20,610 --> 00:13:24,030 I hope that you now understand how the Two's complement 179 00:13:24,030 --> 00:13:27,792 notation works, and I encourage you to try out the practice 180 00:13:27,792 --> 00:13:31,554 questions that will follow and you can check your work by 181 00:13:31,554 --> 00:13:36,000 looking at the answers for this video. We will have two sets of 182 00:13:36,000 --> 00:13:38,680 questions. Here are the first set. 183 00:13:40,470 --> 00:13:43,126 This is the answer to the first set. 184 00:13:49,470 --> 00:13:51,100 Here is the 2nd set. 185 00:13:58,860 --> 00:14:01,947 And here are the answers to the second set.