 Assalamu alaikum students. I'm Vasim Iqram. This is the second lecture in a series of 45 lectures on digital logic design. I hope you have been able to practice with the caveman number system and the binary number system and have been able to convert them into a decimal. So before we start today's lecture, let us review the number systems which we discussed in the last lecture. In the last lecture, we started our discussion by talking about the decimal number system. The decimal number system is a base 10 number system and we have been using this number system from our school days. Each digit in a decimal number system represents up to 10 different values, 0 to 9 of course. The second number system which we discussed was the caveman number system. Of course, it was a hypothetical number system. It is a base 5 number system. What do you think it's a base 5 number system? Well, each digit of the caveman number system can represent up to 5 different values. So it's base 5. The third number system which we discussed was the binary number system. Binary number system as we know is used by digital systems. Each digit or bit of the binary number system can represent up to 2 different values. Now all these 3 number systems are known as positional number systems. Why do we call them positional number systems? Because the exact value of the digit is determined by its position. So for example, in the decimal number system, the first digit which has the position 0 has the weight 1. The next digit which has the position 1 has the weight 10 and so on. Can you give me an example of a number system which is not a positional number system? Well, the answer is the Roman number system. Remember, 1 or its vertical bar represents 1. 2 vertical bars represent 2. 5 is represented by v. 6 is represented by v and a vertical bar and 10 is represented by the character x. So the Roman number system is not a positional number system. In the last lecture, we also looked at the need for converting numbers from one number system to the other. Now for example, all real world values are represented in decimal number system. So 63.51, 97, etc. All digital systems use the binary number system. So we need to convert decimal numbers such as 63.51 into an equivalent binary number which is going to be used by the digital system. Digital systems would be generating values or numbers in terms of binary. So we need to know what is its decimal equivalent. So we need to know how to convert binary numbers to decimal. So let us start by looking at the conversion from decimal to binary and then of course from binary to decimal. So let me talk about the conversion from binary to decimal. There are basically two methods to convert binary numbers into decimal. The first method is the sum of weights method and the second method is the sum of non-zero terms. Let me describe the sum of weights method. In this method, you basically write an expression in terms of the base number and its weight. So for example, you have the number 1101 which is binary. You need to convert it into decimal. You would write an expression. What is the base number? It's 2. What are the weights? So 1101, you would write 2 to power 3, 2 to power 2, 2 to power 1 and 2 to power 0. We are going to be looking at an example which is going to describe this operation. Well, after writing the expression, when you solve the expression, you get some terms. The sum of those terms gives you the actual decimal number. In the other method, the sum of non-zero terms, there you don't need to write an expression. It is a very quick method. You simply need to perform some mental arithmetic. You don't need to use a paper and a pencil. So in the sum of non-zero terms, you simply write the weights of all non-zero values of the binary number. So again, 1011 is the binary number. So you would write the weight of the most significant digit which is a 1 and the weights of the least two binary numbers. You would skip the weight of the zero value. So let us have a look at both these methods through an example. So let us consider the sum of weights method to convert a binary number to a decimal. As I mentioned, you have to write an expression in terms of the base value and weights. So the number to be converted is 10011. The expression can be seen here. It has five terms. The weight of the most significant binary digit which is of course a 1 is 2 raised to the power of 4. The next digit is of course 0. Its weight is 2 raised to the power of 3. The next digit is again 0. It is the weight is of course 2 raised to the power of 2. The last two binary bits are both ones. Their respective weights are 2 raised to the power of 1 and 2 raised to the power of 0. If you solve this expression, you get five terms. The most significant term is 16 followed by 0, another 0, 2 and 1. When you add all these terms, the answer is 19. So the binary number 10011 is equal to 19. The sum of weights method requires an expression to be written. So you have to have a paper and a pencil. You cannot solve it using mental arithmetic. The second method which we discussed was the sum of nonzero terms. Let us consider an example. The number to be converted is again 10011. And this, as we said, we only consider the weights of nonzero values. So what are the nonzero values? The most significant one and the least significant two bits both have a value of 1. So the weights are 16 for the most significant bit and 2 and 1 for the last two or the last two least significant bits. If you sum up these three weights, the answer is 19. Let us consider a second example. The binary number which is to be converted into decimal is 1011.101. So it has an integer part. It has a fraction part. Let us first consider the weights of the integer part. The integer part has four bits. The most significant bit is 1 and the two least significant bits are 1. So the weights are 8 and the weights of the two least significant bits are 2 and 1. Let us consider the fraction part. The bit to the right of the decimal point has a weight of one and a half. And the last bit has the weight of 1 by 8. So if you sum up all these terms, the answer is 11.625. Now you need to remember that in binary, the weights of successive bits increases or decreases by a power of 2. So if you move towards left from the decimal point, the weights increase by a factor of 2. If you move towards right from the decimal point, they decrease by a factor of 2. In the last example, we just saw examples of converting from binary to decimal. The first example used the method of sum of weights. The next two examples, of course, used the sum of nonzero terms. The second method, as I mentioned before, is a quicker, a faster method which simply requires mental arithmetic. It does not require the paper and pencil method. Let us look at the conversion of decimal numbers to binary numbers. The conversion from decimal to binary numbers requires or rather uses two different methods. The first method is the sum of weights method in reverse. How do you do that? Basically you select a binary weight which is less than the decimal number, the highest binary weight which is less than the decimal number. So that particular weight is contributing towards the decimal number. So you mark a one. Next, you select smaller weights which contribute in the decimal number. So all the weights which contribute in the decimal number are marked as one. The weights which do not contribute towards the decimal number, they are marked as zeros. Finally, when you write the binary number you would have ones and zeros. One specify the weights which contribute towards the decimal number. Zeros specify the weights which do not contribute towards the decimal number. So we are going to be looking at the example. The second method which is used to convert decimal numbers to binary numbers is the repeated division by two. So how do you use this method? Basically you divide the decimal number by two. You get a quotient value which you of course note and you get a remainder which again you note. You divide the quotient value by two. You would again get another quotient value and a remainder. So you keep on saving or noting down the remainders and you keep on dividing the quotient value by two. When do you stop? Well, when the quotient value becomes zero that means end of conversion. You just simply write out the remainder values that basically gives you the binary equivalent of the decimal value. Let's have a look at the examples which use the sum of weights method in reverse and of course the repeated division by two. Let us first consider the sum of weights method in reverse to convert a decimal number into binary. Consider the decimal number 392 which is to be converted into binary. The highest weight that is smaller than 392 is 256. The next highest weight is 512 which is not smaller than 392. So as the next step in the conversion process one is written at bit position 8 to represent the weight 256. Why bit position 8? Because bit position 8 represents the weight 256. The weight 256 is subtracted from 392 to result in 136. The process of determining the next highest weight which is smaller than 136 is determined which in this particular case is 128. So the weight smaller than 256 is 128. Thus another one is written at bit position 7 to represent the weight 128. The weight 128 is subtracted from the previous result of subtraction 136 which results in 8. The process of comparing the result with the next highest weight is repeated. The weight 64 is greater than the result 8 thus 0 is added to the binary bits 1 and 1. Successive lower weights 32 and 16 both are larger than 8. Thus two more binary bits are set to 00 at bit positions 5 and 4 respectively. The next lower weight is exactly equal to 8. The corresponding binary bit is set to 1 that is bit position 3. The result 8 is subtracted from the weight 8 resulting in 0. The next three weights are all greater than 0. Therefore 3 0 bits are added to signify 0 weights that is weights 4, 2 and 1 do not contribute towards the decimal number. So bits 2, 1 and 0 all are set to 0. The binary number is 1, 1, 0, 0, 0, 1, 0, 0, 0. Let us consider the second method of converting from decimal to binary using the repeated division by 2. The number to be converted is again 392 decimal. The number 392 is divided by 2. You get a quotient value 196 and the remainder is 0. So you note down the remainder. You divide the quotient value 196 by 2. You get a new quotient value which is 98 and the remainder of course is again 0. So you note down the remainder 0. You continue dividing the quotient value. So now you divide 98 by 2. The new quotient value is 49. The remainder is 0. You note down the remainder. So now you have three remainder values. You continue the process. You divide 49 by 2 again. The new quotient value is 24. The remainder is 1. So if you continue this process, you end up with the last quotient value which is 1. If you divide this by 2, you get the quotient value 0 and a remainder 1. Since the quotient value is 0, you cannot continue any longer. So that means the number 392 has been converted into binary. What is the binary number? So starting from the last remainder, it's 1, 1, 0, 0, 0, 1, 0, 0 and 0. In the last example, we looked at the conversion of decimal numbers into binary using the sum of weights method in reverse and the continued division by 2. Up till now we have been converting integer numbers represented in binary to decimal or integer numbers represented in decimal to binary. We would be dealing with fractions as well as integers. So how can you convert a fraction represented in binary to decimal and a fraction represented in decimal into binary? So let's have a look at methods which allow us to convert fractions from one number system to the other. Let's first have a look at converting fraction represented in binary to decimal. Again, the sum of weights method is used to convert fractions into binary fractions into decimal. Consider an example 0.1101. It's a binary number represented in fraction. We need to convert it into decimal. So sum of weights, what is the weight of the bit immediate to the right of the decimal point? It's 2 raised to power minus 1. The weight of the bit immediate to the right of the decimal point has the weight half. What is the weight of the next bit? It's 1 by 4. The next bit has the value 0. So you don't need to worry about the weight of that particular bit. The last bit has the weight 1 by 16. Now if you just sum up all the weights, what do you get? It's 0.8125. So by using the sum of weights method, you can convert a fraction represented in binary into decimal. Let's have a look at the conversion from a decimal fraction to binary. So the method used there is the repeated multiplication by 2. So let's have a look at the method. But before we look at the example, in the repeated multiplication, you multiply the decimal number by 2. What do you get? You get a number which might have an integer part 1 or a 0 and a fraction. So you note down the integer number and you multiply the fraction again by 2. What do you get? You again get a number which has an integer part and a fraction. So you keep on noting the integer part and you keep on multiplying the fraction part by 2. Ultimately, the fraction part becomes 0. So that means the conversion has to stop. You have completed the conversion. So if you write out the integer parts that you had saved, that gives you the binary representation of the decimal fraction. Now let's have a look at the conversion. Converting fractions from decimal to binary requires repeated multiplication by 2. The decimal number 0.8125 is to be converted into binary is multiplied by 2 which results in 1.625. The integer part 1 is noted and the fraction part 0.625 is multiplied by 2. The result is 1.250. Again, the integer part 1 is noted and the fraction part 0.250 is multiplied by 2. The result is 0.5. Again, the integer part which is 0 is noted and the fraction part 0.5 is multiplied by 2. We are using continued multiplication by 2. By multiplying 0.5 by 2, you get the number 1. The fraction part is 0. So that means you have completely converted the number. You don't need to continue any longer. You note down the integer part. By writing out the integer numbers, you get the converted binary number which is 0.1101. In the example we just saw, we converted a decimal fraction into its binary equivalent using the repeated multiplication by 2. Up till now, we have been converting integers and fractions represented in binary into decimal and vice versa. Now, we need to look at operations which we can perform on numbers. We have been performing addition operations, subtraction, multiplication, division on decimal numbers. So we should be able to perform multiplication, division, subtraction and addition on binary numbers. Let's have a look at binary arithmetic. Let's start by binary addition. Now, in binary addition, you have to add, let's say, two single bit numbers. So what are the possibilities? Both numbers are 0s. So the first number is 0. The second number is 0. What do you get by adding 0 and a 0, of course, in binary? Well, the answer is 0. Let's look at the second possibility. The first number is a 1 and the second number is a 0. What is the answer? The answer is 1, of course, binary. Let's look at the third possibility. The first number is a 0 and the second number is a 1. What is the answer? The answer is 1. Now, let's look at the fourth possibility when both the numbers are binary ones. So the first number is 1. The second number is, again, a 1. What is the answer in terms of binary? It is, of course, 2. But you cannot write 2 because 2 is a decimal number. How do you represent 2 in binary? It's basically a combination of two bits, 1 and a 0. So now, can you represent 1, 0 using a single bit? Of course, you cannot. So how do you represent the sum of 1 and 1? Well, the sum part is considered to be 0 and the carry is a 1. Let's have a look at this using decimal numbers. What happens when you add decimal 9 with decimal 3? The answer is 12. Can you represent 12 using a single decimal digit? Of course, you can't. So what is the sum? The sum is 2. What is the carry? It's 1. So decimal 9 plus 3 gives you a sum part which is 2 and a carry which is 1. Similarly, when you add binary numbers 1 and a 1, the answer is 2. The sum part is 0 and 1 is the carry part. Now, in decimal addition, you can add more than 2 numbers and different numbers could have different sizes. You could be adding a 3-digit number with a 2-digit number. So we can do the same with binary numbers. So let's have a look at the addition of 4 different binary numbers having different bits. Similar to decimal addition, any number of binary numbers having any number of digits can be added together. Thus, the number 1011, the second number 110, the third number 100 and the fourth number 11 can be added together. More significant digits of the second number and the fourth number are considered to be zeros. So let's have a look at the addition. When you add all the bits at position 0, what do you get? You get the answer 2. So, of course, the sum part is 0 and 1 is the carry part. Now, if you add all the bits including the carry at bit position 1, what do you get? The answer is 4. How do you represent 4 in binary? Well, it's 1, 0 and 0. The sum part is 0 and the carry part is 1, 0. Now, you would say, can we have a carry of 2 bits 1 and 0? Well, we can have a carry of 2 bits. I will later give an example using decimal numbers. So let's just first continue with this example. So now, adding all the bits in the third bit including the carry, what do we get? 1, 0 is the carry and we have another one. So the answer is 3. The sum part is 1 and we again have a carry. So now, adding all the bits at position, bit position 3, we have the sum 3. 1 is written at the sum part and 1 is carried over. So the answer is 1, 1, 1, 0 and 0. Now let's consider if we can have a 2-bit carry. Let's consider the number 19 which has to be added 15 times. So how do you add 19 15 times? Well, you start by adding all the 9s in the least significant decimal place. So what do you get by adding 9 15 times? You get 135. What is the sum part? It's 5. What is the carry part? It's 13. So now you know that even in decimal numbers you can have a carry which is of course 2 digits, the number 13. Now what is the answer of adding 19 15 times? So the second decimal place has 15 ones. If you add the carry 13, what do you get? So the answer is 285. The binary addition which you just saw in the example is very similar to the addition which you perform with decimal numbers. Now let us consider binary subtraction. How do we perform binary subtraction? Of course, using binary numbers. Well, let us consider subtracting a single bit number from another single bit number. What are the four possibilities? Well, let us have a look. You subtract a 0 from a 0. What is the result? The result is of course 0. Let us consider the second case. You subtract a 1 from a 0. What is the answer? Well, you have a problem here. You are trying to subtract a larger number, a 1 from a smaller number which is a 0. So as you know in decimal, you cannot subtract a larger number from a smaller number. What do you do? You need to borrow a 1. Similarly, in binary, you would have to borrow a 1. So what happens? 0 becomes 2. When you borrow a 1, the first number becomes a 2. And you subtract a 1, the answer is a 1. So for this particular case, when you subtract a 1 from a 0, you get a difference of 1 and a borrow of 1. Let us just consider subtraction in terms of decimal numbers. You have a number 27 and from 27, you subtract 9. So when you subtract 9 from 7, it is not possible you borrow a 1 from the 2. So you have 17, subtract 9, you get 8. So the difference is 8, you have borrowed a 1. Now let us consider the third case. You subtract a 0 from a larger number, a 1. So what is the difference? Let us say 1. Let us consider the last case, the fourth case. You have two numbers, both are 1s. So you subtract a 1 from a 1. What do you get? The answer is 0. So let us have a look at an example where we see subtraction between two binary numbers. The number 110 from the number 1011. In decimal terms, you are trying to subtract 6 from the number 11. So let us start by looking at bit 0. So you subtract a 0 from 1. The answer is 1. The difference is 1. You do not need to borrow a 1. Let us look at bit position 1. Now you subtract a 1 from a 1. The difference is 0. Let us look at bit 2. At bit position 2, you are trying to subtract a 1 from a 0, which is not possible. What do you do? You borrow a 1 from bit position 3. So now you are trying to subtract a 1 from 2. The difference is 1. You end up with the difference result 101, which is 5. This confirms the subtraction. You had tried to subtract 6 from 11. The answer should be 5. In the example which you just saw, binary subtraction is very similar to decimal subtraction. Now let us look at binary multiplication. Binary multiplication is again very similar to multiplying in decimal. Let us consider the four cases. Multiplying 0 by another number 0. What is the answer? It is 0. Let us consider the second case. Multiply a 0 with a 1. What should be the answer? Again, anything multiplied by 0 gives you 0. Let us consider the third case. 1 multiplied by bit 0. What do you get? Again, a 0. The final case. Multiply a 1 with another 1. What is the answer? 1. Four possible cases. If both the numbers are 1s, only then you would get the answer 1. For all other cases, the answer would be 0. Let us have a look at binary multiplication. Binary multiplication is identical to decimal multiplication. Let us multiply two binary numbers. The first number is 1, 1, 0, 1 and the second number is 1, 0, 1. The first product term is 1, 1, 0, 1. The second product term is all 0s and it is written shifted left by 1 bit. The third product term is again 1, 1, 0, 1 and it is written shifted left by 2 bits. This is what you normally do using decimal numbers. If you add up all the partial product terms, the answer which you get is 1, 0, 0, 0, 0, 0, 1. Now, you can just confirm the result. The first number 1, 1, 0, 1 is decimal 13. The second binary number 1, 0, 1 is decimal 5. The result is equal to 65. The example of binary multiplication again is very similar to multiplication using decimal numbers. Another interesting way of multiplying binary numbers or decimal numbers using a constant value is by shifting the number towards left. Let us consider an example. Let us consider the decimal number 29. Now, if you shift 29 by 1 digit towards left and right is 0 in the least significant digit, what do you get? 2, 9, 0. Now, 2, 9, 0 is like multiplying 29 by 10. Now, if you shift 29 by 2 decimal places towards left, the answer is 2, 9, 0, 0. So, this is something similar to multiplying 29 with 100. So, each decimal place you shift towards left, you are basically multiplying by 10. Let us consider the example of a binary number. Let us consider 1, 0, 1. Now, if you shift binary 1, 0, 1, 1 bit towards left and place is 0 at the least significant bit, what did you get? 1, 0, 1, 0. What is 1, 0, 1 in decimal? It is 5. What is 1, 0, 1, 0? It is 10. So, what have you basically done? By shifting a binary number by 1 bit towards left, you have multiplied it by 2. Why 2? It is base 2 number system. So, if you shift 1, 0, 1 twice towards left, that is by 2 bits, what do you end up with? You get 1, 0, 1, 0, 0. What is the equivalent decimal of this? It is 20. So, you have basically multiplied by 4. Let us now consider binary division. Binary division, again, the process is very similar to dividing numbers than decimal. Let me just explain binary division through an example. Let us have a look at the example. Consider the number, the binary number 1, 1, 0, 1 to be divided by the number 1, 0, 1. The number 1, 1, 0, 1 is equal to decimal 13 and the number 1, 0, 1 is 5. So, when you divide 13 by 5, you get a quotient value of 2 and the remainder 3. Now, I do not need to go into the details. Let us see by looking at the example how 13 is divided by 5 using binary numbers. You end up with the quotient value of 2, which is 1, 0 and the remainder 1, 1, which is equal to 3. Now, we can perform binary division by shifting numbers towards right. As we did in multiplication, if you shift the number towards left, you are basically multiplying it by 10 in the case of decimal numbers and multiplying by 2 in the case of binary numbers. Let us consider the example, 29 decimal, 29. If shifted towards right by 1 digit, you end up with 2.9. Basically, you have divided 29 by 10. If you shift 29 twice towards right, you end up with 0.29, which is division by 100. So, you have divided 29 by 10 because you are using the decimal number system. Let us consider the example of a binary number system. Let us consider 101. If you shift 101 towards right, what do you get? 101.1. What is 101? It is basically 5. What is 101? It is 2.5. You have just divided the binary number by a 2. If you shift 101 towards right by 2 bits, you end up with 0.101, which in fact is 1.25. Up till now, we have been considering binary numbers which are positive numbers. We have not considered negative numbers. We have assumed that all binary numbers are positive. But when we use these binary numbers, then of course, we would be dealing with positive binary numbers as well as negative binary numbers. So, how do you represent a negative binary number? Well, to answer this, let us consider representation of decimal numbers, negative decimal numbers. How do you represent a negative decimal number? Of course, you use the positive or the negative sign. So, plus 9 would have the plus sign and the number 9. Negative 9 would have the negative number, the negative symbol and the number 9. Now, can you use the plus and the minus sign in binary? Well, the answer is no. All symbols, all quantities have to be represented in terms of 1s and 0s. So, in fact, the sign or the symbol plus and the symbol minus have to be represented in terms of 1s and 0s. In digital systems, we deal with unsigned binary numbers and signed binary numbers. So far, we have been dealing with unsigned binary numbers. We had assumed that they are positive. So, we do not need to indicate the positive sign. With signed binary numbers, we need to specify whether the number is positive or negative. So, as we have said, we have to use the binary 1 or 0 to specify the positive and the negative symbol. Now, usually in the signed binary number representation, the most significant bit, the bit towards the extreme left is used to specify the sign. So, if you have 1 there, that indicates the number is negative. If you have the sign bit set to 0, that indicates the number is a positive number. Now, we have two different ways of representing numbers. The unsigned method of representing binary numbers where all numbers are assumed to be positive. And the signed method of representing numbers, binary numbers where you have positive as well as negative numbers. And of course, the signed magnitude representation would be different from the unsigned representation. Now, how would the digital system differentiate between the two representations? Let us suppose you have a number 1101. Now, if you consider the unsigned representation, this is the number 13. If you consider the signed representation, it is negative 5. So, how does a digital system differentiate between the two? Well, it does not know. You need to specify beforehand how to deal with these numbers, whether the number is being represented using unsigned or signed. There is yet another way of representing signed numbers. The method is two's complement. In the two's complement method, we take the original number and calculate its one's complement. What is the one's complement of a binary number? Basically, you invert all the bits. So, for example, the number is 1010. If you take its one's complement, you would have 0101. You have basically inverted all bits. Now, you can take the two's complement from the one's complement by adding a one to the one's complement. So, the number is 0101. You add a one, you end up with 0110. So, this is two's complement of the original number 1010. Now, what is the good thing about two's complement? Well, all positive numbers are represented in their original form, whereas negative numbers are represented in their two's complement form. Consider decimal 13 represented in its two's complement form. So, it is 01101. To represent negative 13, you have to take its two's complement. So, before you take its two's complement, you have to calculate or take its one's complement. It is 10010. To the one's complement of 13, you add a one, you end up with 10011, which is two's complement of negative 13. Consider the addition and subtraction of numbers represented in two's complement form. Let's consider four cases. In the first case, you are adding positive 5 with positive 2. The answer should be positive 7. Positive 5 represented in its two's complement form is 0101. Positive 2 represented in its two's complement form is 0010. The answer is 0111. Again, it is in its two's complement form. Let's consider the second case. Minus 5 is to be added to minus 2. The result is minus 7. Now, minus 5 and minus 2 are both represented in their two's complement form. So, minus 5 is 1011 and minus 2 is 1110. Now, if you add these two numbers, you end up with 1001. Now, 1001 is two's complement of negative 7. Let's consider the third case. In the third case, you add plus 5 with negative 2. The answer should be plus 3. Now, positive 5 is represented in its two's complement form as 0101. Negative 2 is represented in its two's complement form as 1110. If you add these two numbers, you get 0011, which is of course positive 3, represented in its two's complement form. Let's consider the last case. The number minus 5 has to be added to positive 2. The answer is negative 3. Minus 5 represented in its two's complement form as 1011. Positive 2 represented in its two's complement form as 0010. The answer is 1101, which is negative 3 represented in its two's complement form. Now, to obtain the actual magnitude of a negative number, you need to take two's complement of the negative number. So, for example, minus 3 is represented as 1101. If you take the two's complement of 1101, you would end up with 0011. You have just seen an example of representing numbers in their two's complement form. You have also seen an example where we have added and subtracted different numbers represented in their two's complement form. The results of these subtractions and additions would become obvious when we compare two's complement form of binary representation with the signed magnitude form and the unsigned form. So, before we discuss that, let's talk about another topic, the range of binary numbers. How many or rather what is the largest binary number, which we can represent let's say using three bits? Well, the answer is are we talking about unsigned or signed? So, if it's unsigned, then three bits would allow you to represent a minimum number of 0000, which is 0 and a maximum number of 1111, which is 7. So, the range of numbers which you can represent using unsigned representation is from 0 to 7, the largest number is 7, of course, the range is 8. Now, if you consider the three-bit signed magnitude representation of a binary number, the most significant bit is used to represent the sign. So, the least two significant bits would be used to represent the magnitude of the number. So, what is the largest number you can represent using three-bit signed representation? It's positive 3. What is the smallest number? It is negative 3. Consider representing decimal numbers. Consider your calculator which represents up to 8 digits. What is the largest number you can represent on your calculator? When the number is all 9, that is the highest number you can represent in your calculator. Let's suppose the most significant digit on your calculator is used to display the positive or the negative sign. Then, what is the largest positive number you can display on your calculator? Well, when you have 7 9s plus all 9s. What is the smallest number? When the sign is negative and the digits are all set to 9s. So, you have 7 9s. Consider the automator of a car which of course keeps a count of the kilometers traveled. So, if it's a 6 digit automator, what is the largest distance in terms of kilometer it can represent? All 9s. What happens if you add another kilometer or you travel another kilometer? Well, the automator changes over to all zeros. So, of course, you cannot represent a larger number than 6 9s. Similar is the case with binary numbers. So, if you have 3 bits, you cannot go beyond a certain number. Now, we have talked about representing binary numbers using unsigned representation. We have mentioned representing signed numbers using signed magnitude representation. And we have used another way of representing binary numbers using the two's complement method. So, how are these three methods of representing numbers different? What are the ranges of numbers which these three representations can represent? Let's have a look at these three numbers. Let's consider the decimal number range from positive 7 to minus 8. Let's consider the unsigned binary representation of this decimal number range, the signed magnitude representation of this particular decimal number range and the two's complement representation of this decimal number range. Let's first consider the positive decimal numbers from 0 to 7. How would you represent these numbers using the unsigned representation? Well, what is the maximum value? It is 7. What is the range of numbers? Basically, you have 8 values starting from 0 to 7. How many bits do you require to represent these decimal numbers using unsigned representation? Well, the answer is 3. So, 0 0 0 would represent the decimal number 0. 1 1 1 would represent the decimal number 7. So, we have defined values from 0 to 7 using 3 bits. What is the general formula? It's 2 raised to power n. So, n in this case is 3. So, the range of values is 2 raised to power 3 which is 8. What is the maximum positive value which we can represent? It is of course 7. So, the formula is 2 raised to power n minus 1. Let's consider the signed magnitude method of representing decimal numbers from 0 to 7. Well, in the signed magnitude method we said we use an additional bit to represent the sign of the number. So, how do we represent the positive sign? The bit should be set to 0. So, instead of 3 bits we have to use a combination of 4 bits. So, positive 7 is represented by 0 1 1 1. The most significant bit 0 represents the sign, the positive sign. The 3 least significant bits 1 1 1 represent the magnitude which is 7. Similarly, the smallest positive number which is 0 is represented by all 0 bits 0 0 0 0. The most significant 0 bit represents the sign and the 3 least significant bits represent the magnitude of course. The general formula for this is 2 raised to power n minus 1. So, in this particular case what is n? It is 4. We are using 4 bits. So, 2 raised to power 4 minus 1 is basically 8. So, the range of numbers is 8 from 0 to 7. What is the largest value? The formula is 2 raised to power n minus 1 minus 1. Now, let's consider the 2's complement method of representing positive decimal numbers from 0 to 7. Now, as we said positive values are represented in their original form using 2's complement method. So, there is no difference between the sign magnitude representation and 2's complement method of representing positive decimal values as you can see in the diagram. The formulas used are again very similar. Now, let's consider the representation of negative decimal numbers from minus 1 to minus 8. Now, can you represent these negative numbers using the unsigned binary representation? Well, the answer is no. Unsigned binary representation is used to represent only positive numbers. Now, how would you represent the negative numbers using the signed magnitude representation? Well, as we have said the most significant bit represents the sign. What is the sign? It's negative. So, the most significant bit is set to 1 and the lower 3 bits would represent the magnitude. So, for example, minus 1 is 1 0 0 1. The most significant bit represents the sign and the lower 3 bits represent the magnitude 1. The largest number which we can represent using 4 bits is minus 7. Can we represent minus 8? The answer is no. Why? Well, 8 requires 4 bits. Positive 8 is 1 0 0 0. So, what is negative 8? You would require 5 bits, 1 the negative sign and 1 0 0 0 the magnitude. So, using 4 bits you cannot represent the decimal number minus 8. The formula to represent negative numbers using sign magnitude is shown. Let's have a look at 2's complement of representing negative decimal numbers. As we had said earlier, negative numbers are represented in their 2's complement form. So, negative 1 is 1 1 1 1. Of course, this is in its 2's complement form. Minus 7 is represented as 1 0 0 1. Minus 8 is represented as 1 0 0 0. We have just looked at 3 different ways of representing the binary numbers. The unsigned representation, the sign representation and the 2's complement representation. We would be looking at these representations again in the next lecture. So, let's end today's lecture. We have discussed a number of topics. Please do practice till we meet again. Good luck. Sa'hafiz and As-Salaamu Alaikum.