Date post: | 17-Dec-2015 |
Category: |
Documents |
Upload: | wilfred-young |
View: | 266 times |
Download: | 3 times |
Number Systems & Number Systems & OperationsOperations
Part IIPart II
Arithmetic Operations with Arithmetic Operations with Signed NumbersSigned Numbers
Because the 2’s complement form for Because the 2’s complement form for representing signed numbers is the most representing signed numbers is the most widely used in computer systems. We’ll widely used in computer systems. We’ll limit to 2’s complement arithmetic on:limit to 2’s complement arithmetic on: AdditionAddition SubtractionSubtraction MultiplicationMultiplication DivisionDivision
AdditionAddition
4 cases that can occur when 2 signed 4 cases that can occur when 2 signed numbers are added:numbers are added: Both numbers positiveBoth numbers positive Positive number with magnitude larger than Positive number with magnitude larger than
negative numbernegative number Negative number with magnitude larger than Negative number with magnitude larger than
positive numberpositive number Both numbers negative Both numbers negative
AdditionAddition
Both numbers positive:Both numbers positive:
ex: ex: 00000111 00000111 7 7
+00000100+00000100 +4+4
0000101100001011 1111
The sum is positive and is therefore in true The sum is positive and is therefore in true (uncomplemented) binary.(uncomplemented) binary.
AdditionAddition
Positive number with magnitude larger Positive number with magnitude larger than negative number:than negative number:
ex: ex: 00001111 00001111 15 15
+11111010+11111010 + -6+ -6
11 00001001 00001001 9 9
The final carry bit is discarded. The sum is The final carry bit is discarded. The sum is positive and is therefore in true positive and is therefore in true (uncomplemented) binary. (uncomplemented) binary.
Discard carry
AdditionAddition
Negative number with magnitude larger Negative number with magnitude larger than positive number:than positive number:
ex: ex: 00010000 00010000 16 16
+11101000+11101000 + -24+ -24
1111100011111000 -8 -8
The sum is negative and therefore in 2’s The sum is negative and therefore in 2’s complement form. complement form.
AdditionAddition
Both numbers negative:Both numbers negative:
ex: ex: 11111011 11111011 -5 -5
+11110111+11110111 + -9+ -9
11 11110010 11110010 -14 -14
The final carry bit is discarded. The sum is The final carry bit is discarded. The sum is negative and therefore in 2’s complement negative and therefore in 2’s complement form. form.
Discard carry
AdditionAddition
Remark:Remark: The negative numbers are stored in 2’s The negative numbers are stored in 2’s
complement form so, as you can see, the complement form so, as you can see, the addition process is very simple: addition process is very simple: Add the two Add the two numbers and discard any numbers and discard any finalfinal carry bit carry bit..
AdditionAddition
Overflow condition:Overflow condition: When two numbers are added When two numbers are added
and the number of bits and the number of bits required to represent the sum required to represent the sum exceeds the number of bits in exceeds the number of bits in the two numbers, an the two numbers, an overflowoverflow results as indicated by an results as indicated by an incorrect sign bit.incorrect sign bit.
An overflow can occur only An overflow can occur only when both numbers are + or -.when both numbers are + or -.
ex: ex: 0111110101111101 125 125 +00111010+00111010 + 58 + 58 1101101110110111 183 183
Magnitude incorrect
Sign incorrect
AdditionAdditionNumbers are added two at a time:Numbers are added two at a time: Computer add strings of numbers two numbers Computer add strings of numbers two numbers
at a time.at a time.ex:ex: add the signed numbers: add the signed numbers: 0100010001000100, 00011011, , 00011011, 0000111000001110, ,
and and 0001001000010010
6868 01000100 01000100
+ 27+ 27 + 00011011+ 00011011 Add 1Add 1stst two two numbersnumbers
9595 01011111 01011111 11stst sum sum
+ 14+ 14 + 00001110+ 00001110 Add 3Add 3rdrd number number
109109 01101101 01101101 22ndnd sum sum
+ 18+ 18 + 00010010+ 00010010 Add 4Add 4thth number number
127127 01111111 01111111 Final sumFinal sum
SubtractionSubtraction
Subtraction is Subtraction is a special casea special case of addition. of addition. Subtraction is addition with the sign of the Subtraction is addition with the sign of the
subtrahend changed.subtrahend changed. The result of a subtraction is called the The result of a subtraction is called the
difference.difference.
The sign of a positive or negative binary is The sign of a positive or negative binary is changed by taking it’s 2’s complement.changed by taking it’s 2’s complement.
_______________________________
Subtrahend = ตั�วลบ, Minuend = ตั�วตั��ง
SubtractionSubtraction
Since subtraction is simply an addition Since subtraction is simply an addition with the sign of the subtrahend changed, with the sign of the subtrahend changed, the process is stated as follows:the process is stated as follows: To subtract two signed numbers, take the 2’s To subtract two signed numbers, take the 2’s
complement of the subtrahend and add. complement of the subtrahend and add. Discard any final carryDiscard any final carry..
SubtractionSubtraction
ex:ex: Perform each of the following subtraction of the signed numbers: Perform each of the following subtraction of the signed numbers:
(a) 00001000 – 00000011(a) 00001000 – 00000011 (b) 00001100 – (b) 00001100 – 1111011111110111
(c) 11100111 – 00010011(c) 11100111 – 00010011 (d) 10001000 - (d) 10001000 - 1110001011100010
(a) 00001000(a) 00001000 8 8 (b) 00001100(b) 00001100 12 12
+11111101+11111101 + -3+ -3 +00001001+00001001 + 9+ 9
110000010100000101 55 00010101 00010101 2121
(c) 11100111(c) 11100111 -25-25 (d) 10001000 (d) 10001000 -120 -120
+11101101+11101101 + -19+ -19 +00011110+00011110 + 30+ 30
111101010011010100 -44-44 10100110 10100110 -90 -90
MultiplicationMultiplication
The multiplication operation in most The multiplication operation in most computer is accomplished using addition.computer is accomplished using addition. There are 2 basic methods:There are 2 basic methods:
Direct additionDirect addition
Partial productsPartial products
MultiplicationMultiplication
Direct additionDirect addition Add the multiplicand a number of times equal Add the multiplicand a number of times equal
to the multiplier.to the multiplier.For example, 8x3 = 8+8+8 = 24For example, 8x3 = 8+8+8 = 24Disadvantage Disadvantage lengthy operations lengthy operations
When two binary numbers are multiplied, both When two binary numbers are multiplied, both numbers MUST BE in numbers MUST BE in true (uncomplemented) true (uncomplemented) formform..
Let’s try multiply the signed binary numbers: Let’s try multiply the signed binary numbers: 010011010100110122 and 00000100 and 0000010022 using direct using direct addition.addition.
_______________________________
Multiplier = ตั�วคูณ, multiplicand =
ตั�วตั��ง
MultiplicationMultiplication
Partial productsPartial products The multiplicand is The multiplicand is
multiplied by each multiplied by each multiplier digit beginning multiplier digit beginning with the LSD.with the LSD.
239 multiplicandx 123 multiplier 717 478+239 .
MultiplicationMultiplication
Partial productsPartial products The result of the The result of the
multiplication of the multiplication of the multiplicand by a multiplier multiplicand by a multiplier digit is called a digit is called a partial partial productproduct..
239 multiplicandx 123 multiplier 717 1st part prod
478 2nd part prod
+239 3rd part prod
MultiplicationMultiplication
Partial productsPartial products Each successive partial Each successive partial
product is shifted one product is shifted one place to the left and when place to the left and when all the partial products all the partial products have been produced, they have been produced, they are added to get the final are added to get the final product.product.
239 multiplicandx 123 multiplier 717 1st part prod
478 2nd part prod
+239 3rd part prod
29397 Final Product
MultiplicationMultiplication
The sign of the product of a multiplication The sign of the product of a multiplication depends on the signs of the multiplicand depends on the signs of the multiplicand and the multiplier according to the and the multiplier according to the following two rules:following two rules: If the signs are the same, the product is If the signs are the same, the product is
positivepositive.. If the signs are different, the product is If the signs are different, the product is
negativenegative..
MultiplicationMultiplication
Step 1:Step 1: Determine if Determine if the signs of the the signs of the multiplicand and multiplicand and multiplier are the multiplier are the same or different. same or different. This determines This determines what the sign of the what the sign of the product will be.product will be.
01010011 (multiplicand)11000101 (multiplier)
Multiplicand +Multiplier -Product -
MultiplicationMultiplication
Step 2:Step 2: Change any Change any negative number to negative number to true form. Because true form. Because most computers store most computers store negative numbers in negative numbers in 2’s comp, a 2’s comp 2’s comp, a 2’s comp operation is required to operation is required to get the negative get the negative number into true form.number into true form.
01010011 (multiplicand)11000101 (multiplier)
00111011 (2’s comp)
MultiplicationMultiplication
Step 3:Step 3: Starting with Starting with the LSB (multiplier), the LSB (multiplier), generate the partial generate the partial products. Shift each products. Shift each successive partial successive partial product one bit to the product one bit to the left.left.Step 4: Step 4: add each add each successive partial successive partial product to the sum of product to the sum of the previous partial the previous partial products to get the products to get the final product.final product.
01010011 (multiplicand)11000101 (multiplier)
1010011 x 0111011 1010011 + 1010011 . 11111001 + 0000000 . 011111001 + 1010011 . 1110010001 + 1010011 . 100011000001 + 1010011 . 1001100100001 + 0000000 . 1001100100001
MultiplicationMultiplication
Step 4: Step 4: if the sign if the sign bit was determined bit was determined in step 1 is in step 1 is negative, take the negative, take the 2’s comp of the 2’s comp of the product. If positive, product. If positive, leave the product in leave the product in true form. Attach true form. Attach the sign bit to the the sign bit to the product.product.
01010011 (multiplicand)11000101 (multiplier)
1001100100001 (final)
0110011011111 (2’s comp)
According to step 1 the sign bit of the product must be 1 (negative).Hence:
10110011011111
DivisionDivision
The number in a division are the dividend, The number in a division are the dividend, the devisor, and the quotient.the devisor, and the quotient.
dividend dividend = quotient= quotient
devisordevisor
The division op in computer is The division op in computer is accomplished using subtraction. Since accomplished using subtraction. Since subtraction is done with an adder, division subtraction is done with an adder, division can also be accomplished with an adder.can also be accomplished with an adder.
DivisionDivision
The quotient is the The quotient is the number of times that number of times that the divisor will go into the divisor will go into the dividend. This the dividend. This means that the divisor means that the divisor can be subtracted from can be subtracted from the dividend a number the dividend a number of times equal to the of times equal to the quotient. (let’s do 21/7)quotient. (let’s do 21/7)
21 - 7 14 - 7 7 - 7 0
The divisor was subtracted from the dividend 3 times before a remainder of zero was obtained. Therefore, the quotient is 3.
DivisionDivision
The The signsign of the quotient depends on the of the quotient depends on the signs of the dividend and the divisor signs of the dividend and the divisor according to the following two rules:according to the following two rules: If the signs are the same, the quotient is If the signs are the same, the quotient is
positivepositive.. If the signs are different, the quotient is If the signs are different, the quotient is
negativenegative..
When 2 binary numbers are divided, both When 2 binary numbers are divided, both numbers MUST BE in true form.numbers MUST BE in true form.
DivisionDivision
Step 1:Step 1: Determine Determine if the signs of the if the signs of the dividend and dividend and divisor are the divisor are the same or different. same or different. This determines This determines what the sign bit of what the sign bit of the quotient will the quotient will be. Initialize the be. Initialize the quotient to zero.quotient to zero.
01100100 (dividend)00011001 (divisor)
Dividend +Divisor +Quotient +
DivisionDivision
Step 2:Step 2: Subtract the Subtract the divisor from the divisor from the dividend using 2’s dividend using 2’s complement addition complement addition to get the first partial to get the first partial remainder and add 1 remainder and add 1 to the quotient. to the quotient. If this partial If this partial
remainder is positive, remainder is positive, go to step 3.go to step 3.
If the partial If the partial remainder is zero or remainder is zero or negative, the division negative, the division is complete.is complete.
01100100 (dividend)00011001 (divisor)
01100100+ 11100111 (2’s comp) 101001011
Note: The final carries are discarded.
Quotient = 00000000+00000001 = 00000001
DivisionDivisionStep 3:Step 3: Subtract the Subtract the divisor from the divisor from the partial remainder and partial remainder and add 1 to the quotient. add 1 to the quotient. If this partial If this partial
remainder is positive, remainder is positive, repeat for the next repeat for the next partial remainder.partial remainder.
If the result is zero or If the result is zero or negative, the division negative, the division is complete.is complete.
01100100 (dividend)00011001 (divisor)
01001011+ 11100111 (2’s comp) 100110010
00110010+ 11100111 (2’s comp) 100011001
00011001+ 11100111 (2’s comp) 100000000
Quotient = 00000001+00000001 = 00000010
Quotient = 00000010+00000001 = 00000011
Quotient = 00000011+00000001 = 00000100
Stop when the result is zero (or negative)
Quotient = 4
Hexadecimal and Octal Hexadecimal and Octal NumbersNumbers
Hexadecimal NumbersHexadecimal Numbers
We will call it for short as “hex”.We will call it for short as “hex”.It has 16 characters. Digits 0-9 and letters It has 16 characters. Digits 0-9 and letters A-F.A-F.It used primarily as a compact way of It used primarily as a compact way of displaying or writing binary numbers since displaying or writing binary numbers since it is very easy to convert between bin and it is very easy to convert between bin and hex.hex. Hex is widely used in computer and Hex is widely used in computer and
microprocessor applications.microprocessor applications.
Hexadecimal NumbersHexadecimal NumbersDecimalDecimal BinaryBinary HexadecimalHexadecimal
00 00000000 00
11 00010001 11
22 00100010 22
33 00110011 33
44 01000100 44
55 01010101 55
66 01100110 66
77 01110111 77
88 10001000 88
99 10011001 99
1010 10101010 AA
1111 10111011 BB
1212 11001100 CC
1313 11011101 DD
1414 11101110 EE
1515 11111111 FF
Hexadecimal NumbersHexadecimal Numbers
If you see If you see ‘h’‘h’ mixing in numbers (in the mixing in numbers (in the context of computer systems), please note context of computer systems), please note that it’s most likely that the numbers are that it’s most likely that the numbers are hhexadecimalexadecimal numbers. (Be careful. numbers. (Be careful. ‘h’‘h’ is is not one of A-F using in hex).not one of A-F using in hex). For exampleFor example
16h = 0001011016h = 0001011022
0Dh = 000011010Dh = 0000110122
Hexadecimal NumbersHexadecimal Numbers
Bin-to-Hex ConversionBin-to-Hex Conversion Simply break the binary number into 4-bit Simply break the binary number into 4-bit
groups, starting at the right-most bit and groups, starting at the right-most bit and replace each 4-bit group with the equivalent replace each 4-bit group with the equivalent hex symbol.hex symbol.
(a) 1100101001010111(a) 1100101001010111 (b) 111111000101101001(b) 111111000101101001
11001100101010100101010101110111 0000111111111111000100010110011010011001
C C A A 5 5 77 3 3 F F 1 1 6 6 99
= CA57= CA571616 = 3F169= 3F1691616
Hexadecimal NumbersHexadecimal Numbers
Hex-to-Bin ConversionHex-to-Bin Conversion Reverse the process (of bin-to-hex) and replace Reverse the process (of bin-to-hex) and replace
each hex symbol with the appropriate four bits.each hex symbol with the appropriate four bits.
ex: Determine the binary numbers for the following hex numbers:ex: Determine the binary numbers for the following hex numbers:
(a) 10A4h(a) 10A4h (b) CF8Eh (b) CF8Eh (c) 9742h (c) 9742h 1 1 00 A A 44 C C FF 8 8 EE 9 9 77 4 4 22
00000011000000001010101001000100 1100110011111111100010001110 1110 10011001011101110100010000100010
Hexadecimal NumbersHexadecimal Numbers
Hex-to-Dec ConversionHex-to-Dec Conversion 2 methods:2 methods:
Hex-to-Bin first and then Bin-to-Dec.Hex-to-Bin first and then Bin-to-Dec.
Multiply the decimal values of each hex digits by its Multiply the decimal values of each hex digits by its weight and then take the sum of these products. weight and then take the sum of these products.
Hexadecimal NumbersHexadecimal Numbers
Hex-to-Dec ConversionHex-to-Dec Conversion Hex-to-Bin first and then Bin-to-DecHex-to-Bin first and then Bin-to-Dec
ex: Convert the following hex numbers to decimal:ex: Convert the following hex numbers to decimal:
(a) 1Ch(a) 1Ch
11CCh = h = 0001000111001100 = 16+8+4 = 28 = 16+8+4 = 281010
(b) A85h(b) A85h
AA8855h = h = 101010101000100001010101 = 2048+512+128+4+1 = 2693 = 2048+512+128+4+1 = 26931010
Hexadecimal NumbersHexadecimal Numbers
Hex-to-Dec ConversionHex-to-Dec Conversion Multiply the decimal values of each hex digits by its Multiply the decimal values of each hex digits by its
weight and then take the sum of these products.weight and then take the sum of these products.
ex: Convert the following hex numbers to decimal:ex: Convert the following hex numbers to decimal:
(a) E5h(a) E5h
E5h = (Ex16)+(5x1) = (14x16)+5 = 224+5 = 229E5h = (Ex16)+(5x1) = (14x16)+5 = 224+5 = 2291010
(b) B2F8h(b) B2F8h B2F8h = (Bx4096)+(2x256)+(Fx16)+(8x1)B2F8h = (Bx4096)+(2x256)+(Fx16)+(8x1) = (11x4096)+(2x256)+(15x16)+(8x1)= (11x4096)+(2x256)+(15x16)+(8x1)
= 45,056+512+240+8 = 45,816= 45,056+512+240+8 = 45,8161010
Hexadecimal NumbersHexadecimal NumbersDec-to-Hex conversionDec-to-Hex conversion Repeated division of a dec number by 16Repeated division of a dec number by 16
ex: Convert the dec number 650 to hexex: Convert the dec number 650 to hex
650/16 = 650/16 = 4040..625625 0.6250.625x16 = 10 = x16 = 10 = AA
4040/16 = /16 = 22..55 0.50.5x16 = 8 = x16 = 8 = 88
22/16 = /16 = 00..125125 0.1250.125x16 = 2 = x16 = 2 = 22
Stop when whole number quotient is ZERO.
MSD
LSD
Hence 65010 = 28Ah
Octal NumbersOctal Numbers
Like the hex, the “oct” provides a convenient Like the hex, the “oct” provides a convenient way to express binary numbers and codes. (btw, way to express binary numbers and codes. (btw, it’s not as commonly used as hex).it’s not as commonly used as hex).8 digits: 0-78 digits: 0-7 0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17,20,…0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17,20,…
Operations we learn about Operations we learn about hexhex so far work the so far work the same way on same way on octoct just mark this: just mark this: Hex = 4 binary bitsHex = 4 binary bits Oct = 3 binary bitsOct = 3 binary bits
Now, let’s crack the following exercises…Now, let’s crack the following exercises…
Octal NumbersOctal Numbers
Bin-to-Oct ConversionBin-to-Oct Conversion(a) 110101(a) 110101 (b) 101111001 (b) 101111001 (c) 100110011010 (c) 100110011010 (d) 11010000100(d) 11010000100
Oct-to-Bin ConversionOct-to-Bin Conversion(a) 13(a) 1388 (b) 25 (b) 2588 (c) 140 (c) 14088 (d) 7526 (d) 752688
Oct-to-Dec ConversionOct-to-Dec Conversion (a) 2374(a) 237488
Dec-to-Oct ConversionDec-to-Oct Conversion(a) 359(a) 3591010