the next topic is two's complement addition and subtraction supposing let's say we have two positive numbers plus 3 and + 4 you know that its result will be + 7 in two's complement addition you do not do anything for positive numbers which means you just take the binary sequence as it is so 3 is nothing but 0 0 1 1 that's positive 3 in two's complement and 4 is 0 1 0 0 and you can add it up directly so that's + 7 okay it works as normal binary addition now let's do this one which is + 5 - 6 so you're asked to do this computation but one of the numbers is negative so whenever a negative number is involved you have to use two's complement so for example postive 5 is nothing but 0 1 0 1 in binary now when you have -6 first take six so 6 would be 0 1 1 0 now if you want to convert it into -6 first flip all the bits 1 1 0 0 1 and add one to it so 1 + 1 is 0 carry 1 1 0 1 so next you add + 5 and -6 so that's 0 1 0 1 1 0 1 0 and that would be 1 one one 1 now this a small difference that you have to observe whenever the MSB in your result is a zero your final answer will be the number itself with the binary sequence so that's seven here and when you have a one as your MSB it's going to be a negative and we have to convert this into decimal as we have seen in the previous class so this is negative flip all the bits and add one so that's 0 0 0 1 which is equals to 1 so your answer is -1 let's take another example what is - 5 + 6 technically it should be 1 so let's see how to get that so you know that 6 is 01 1 0 now you have a NE 5 so First Take Five which is 0 1 0 1 flip all the bits add one to it so that's -5 and two's complement so add add it up one one 0 carry one 0 carry one 0 and you get a one in two's complement whenever a carry is generated as the last bit you can ignore the carry so this is equivalent to one positive 1 because the MSB is zero which means it's a positive number so you have - 5 + 6 is postive 1 and both of these match up let's take another example so you have 23 - 6 so 23 is uh it's a positive number so 0 16 + 4 + 2 + 1 so that's 23 you can you can check it out so so this is 1 2 4 8 16 32 so 16 + 4 20 20 + 2 22 + 1 23 and then you have 6 so you have -6 so take six and convert it into binary so that's 0 1 1 0 now we need to make sure that the number of bits in six and the number of bits bits and 23 are the same so 23 has six bits 6 has four bits what I'm going to do is add into extra zeros okay now flip all the bits add one so that's that's -6 put it here 1 one 1 0 1 0 that's one that's 0 carry one that's one carry one and 0 carry one and we ignore the last carry out so this is equivalent to now the MSB is a zero so it's positive and then you have 16 + 1 that's 17 so 23 - 6 is POS 17 both of these match up so that's how you do to complement addition and subtraction