Beruflich Dokumente
Kultur Dokumente
5. If the summation does not produce an end carry, this corresponds to the M < N case. The result is a negative number. Take the rs complement of the sum and place a negative sign in front. Subtraction of unsigned numbers can also be done by means of the (r 1)s complement. Remember that the (r 1)s complement is one less than the rs complement. Because of this, the result of adding the minuend to the (r 1)s complement of the subtrahend produces a sum that is one less than the correct difference when an end carry occurs. Removing the end carry and adding 1 to the sum is referred to as an end-around carry. When the sum does not produce an end carry, the result is a negative number. In this case, take the (r 1)s complement of the sum and place a negative sign in front. 1/6
Example (Prob. 1.18 from Mano, 2007): Perform subtraction on the given unsigned numbers using the 2s complement of the subtrahend. Where the result should be negative, find its 2s complement and affix a minus sign. Verify your answer. a) 10011 10001 (b) 1001 101000 Solutions: a) The 2s complement of the subtrahend 10001 = 01111 1111 10011 +01111 100010 carry bits
Since the summation produces an end carry the result is positive. Discard the end carry; the result is a positive number. The result of the subtraction: 10011 10001 = 00010 Verification of the result: Minuend : (10011)2 = 124 + 023 + 022 + 121 + 120 = 16 + 2 + 1 = (19)10 Subtrahend : (10001)2 = 124 + 023 + 022 + 021 + 120 = 16 + 1 = (17)10 Difference : (00010)2 = 024 + 023 + 022 + 121 + 020 = 2 = (2)10 The result of the subtraction in decimal number system is 19 17 = 2. Thus, the result is verified. b) Here, the minuend (1001) has 4 digits and the subtrahend (101000) has 6 digits. At first we have to equate the number of digits of the minuend and the subtrahend. Therefore, we add two zeros the left of the most significant number of the minuend and make it (001001). The 2s complement of the subtrahend 101000 = 011000 11 001001 +011000 100001 carry bits
Since the summation does not produce an end carry the result is a negative number. Take the 2s complement of the sum and place a negative sign in front. The 2s complement of the result (100001) is 011111 The result of the subtraction: 1001 101000 = 011111 Verification of the result: Minuend : (001001)2 = 025 + 024 + 123 + 022 + 021 + 120 = 8 + 1 = (9)10 Subtrahend : (101000)2 = 125 + 024 + 123 + 022 + 021 + 020 = 32 + 8 = (40)10 Difference : (011111)2 = (025 +124 + 123 + 122 + 121 + 120) = (16 + 8 + 4 + 2 + 1) = (31)10 The result of the subtraction in decimal number system is 9 40 = 31. Thus, the result is verified.
2/6
5. If the summation does not produce an end carry, the leftmost bit is the sign bit. 6. The same procedure can be applied to the (r 1)s complement system by including the end-around carry as it is done with unsigned numbers. Signed-Complement Representation (for Binary Numbers) In this system, a negative number is always indicated by its complement. This system is more convenient when arithmetic operations are implemented in a computer. The signed-complement system negates a number by taking its complement including the sign bit. The complement of the positive number is taken including the sign bit. Since positive numbers always start with 0 (plus) in the leftmost position, the complement will always start with a 1, indicating a negative number. The signed-complement system can use either the 1s or the 2s complement, but the 2s complement is the most common. 3/6
As an example, consider the number 9, represented in binary with eight bits. o There is only one way to represent +9 Signed-magnitude representation of 9 : 00001001 : 10001001 o There are three different ways to represent 9 with eight digits: Signed-1s complement representation 9 : 1 1 1 1 0 1 1 0 Signed-2s complement representation 9 : 1 1 1 1 0 1 1 1 minus sign Note that all negative numbers have a 1 in the left most bit position. Thus, we can distinguish them from the positive numbers. 1s complement system is useful as a logical operation, since the change of 1 to 0 or 0 to 1 is equivalent to a logical complement operation, as will be shown in the Boolean algebra chapter. The same procedure can be applied to the 1s complement system by including the end-around carry as it is done with unsigned numbers. Addition and Subtraction in Signed-2s Complement System In the signed-2s complement system, - Positive binary numbers (start with 0) are represented in the signed-magnitude form. - Negative binary numbers (start with 1) are represented in the signed-2s complement form. The same procedure is applied for the addition and subtraction of numbers M and N: 1. The number of digits of M and N should be the same. 2. Negative numbers must initially be in the signed 2s complement form. 3. Perform the operation M + N 4. Discard the end carry bit (if any). Then, the leftmost bit is the sign bit. If the sign bit is 0, the result is positive. If the sign bit is 1, the result is negative and in 2s complement form. Take the 2s complement of the result and place a minus sign in front.
This procedure is adopted because a subtraction operation can be changed to an addition operation if the sign of the subtrahend is changed as shown in the following relationship: (A) (+B) = (A) + (B); (A) (B) = (A) + (+B). Changing a positive number to a negative number is easily done by taking the 2s complements of the positive number. Reverse is also true, because the complement of a negative number in complement form produces the equivalent positive number.
4/6
Example (Prob. 1.20 from Mano 2007) Convert decimal +49 and +29 to binary, using the signed-2s complement representation and enough digits to accommodate the numbers. Then perform the binary equivalent of following. Convert the numbers back to decimal and verify that they are correct. a) (+29) + (49) b) (29) + (+49) c) (29) + (49) Solution: Conversion of 49 from decimal to binary: Integer Dividend 49 24 12 6 3 1 Integer Divider Quotient Remainder 2 24 1 (LSB) 2 12 0 2 6 0 2 3 0 2 1 1 2 0 1 (MSB)
(49)10 = (1 1 0 0 0 1)2
Conversion of 29 from decimal to binary: Integer Dividend 29 14 7 3 1 Integer Divider Quotient Remainder 2 14 1 (LSB) 2 7 0 2 3 1 2 1 1 2 0 1 (MSB)
(29)10 = (1 1 1 0 1)2
In order to equate the number of bits of both binary numbers we add a zero to the most significant bit (MSB) position of the binary equivalent of decimal 29, and obtain (29)10 = (0 1 1 1 0 1)2 Lets express the positive binary numbers by placing a zero (0) to the left of the MSBs. (+49)10 = (0 1 1 0 0 0 1)2 ; (+29)10 = (0 0 1 1 1 0 1)2
Sign bits (0: Positive) Let take the 2s complement of these binary numbers to obtain the corresponding negative numbers. (49)10 = 2s complement of (0 1 1 0 0 0 1) = [1s complement (0 1 1 0 0 0 1) + 1] = (1 0 0 1 1 1 0 + 1)2 = (1 0 0 1 1 1 1)2 (29)10 = 2s complement of (0 0 1 1 1 0 1) = [1s complement (0 0 1 1 1 0 1) + 1] = (1 1 0 0 0 1 0 + 1)2 = (1 1 0 0 0 1 1)2 a) (+29)10 + (49)10 = (0 0 1 1 1 0 1)2 + (1 0 0 1 1 1 1)2 = ? +29 49 20 1 1 1 0 0 1 1 + 1 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 carry bits (There is no end carry and the sign bit is 1) 5/6
Since there is no end carry and the sign bit is 1, the result is negative. This means that the result is in 2s complement form. We take the 2s complement of the result and place a minus sign in front as follows: 2s complement of ( 1 1 0 1 1 0 0 )2 = (0 0 1 0 1 0 0)2 = (124 + 122) = (20)10 Leave unchanged Replace 1s with 0s and 0s with 1s. b) (29)10 + (+49)10 = (1 1 0 0 0 1 1)2 + (0 1 1 0 0 0 1)2 = ? 29 +49 +20 1 11 1100011 +0110001 10010100 carry bits +(0 1 0 1 0 0)2 = +(124 + 122) = + (20)10
Sign bit is 0, the sign is positive. The result is not in complement form. Remove the end carry. c) (29)10 + (49)10 = (1 1 0 0 0 1 1)2 + (1 0 0 1 1 1 1)2 = ? To accommodate the overflow values we must increase the word size by 1. Add 1 bit to the left of the sign bits. This is called sign extension. 29 49 78 11 1111 11100011 + 11001111 110110010 carry bits (1 0 1 1 0 0 1 0 )2
Sign bit is 1, the sign is negative. The result is in complement form. Remove the last carry. The 2s complement of (1 0 1 1 0 0 1 0 )2 = (0 1 0 0 1 1 1 0)2 = (126 + 123+ 122+ 121) Leave unchanged Replace 1s with 0s and 0s with 1s. Thus, the result is (29)10 + (49)10 = (1 1 0 0 0 1 1)2 + (1 0 0 1 1 1 1)2 = (0 1 0 0 1 1 1 0)2 = (126 + 123+ 122+ 121)10 = (78)10 Note: In signed 2s complement system, when the minuend and the subtrahend are both negative numbers we have to make sign extension. Otherwise, after removing the end carry from the result. 0 bit is left as the sign bit which is wrong.
6/6