Computer Arithmetic
Computer Arithmetic
Computer
Arithmetic
Bhashini Wijewickrama
By the end of this lesson, students will be
able to;
• Apply basic arithmetic operations.
• Describe two’s complement in integer
representation.
Learning • Describe sign-magnitude representation.
Outcomes • Describe floating point representation
mechanism.
• Compute arithmetic operations using
integers and floating point numbers.
Binary Arithmetic
Binary only 0 or 1.
Example 1 11
1001101
+1 1 0 0 1 1 0
1 0 1 1 0 0 1 12
• Subtraction is slightly more
complicated.
Example 2
1110111
−1 0 0 1 1 0 1
0 1 0 1 0 1 02
• The multiplier digits are always 1 or 0:
Binary • Therefore, the partial products are
Multiplication equal either to the multiplicand or to 0.
Multiply the binary numbers 11012
and1102 .
1101
Example × 110
0000
1101
1101
1001110
Binary Division
Devide the binary numbers 10011102
and1102 .
0 110 1
110 1001110
Example 110
0111
110
00110
Signed Binary Numbers
• In tradition we use the ‘+’ sign before a number to indicate it as a positive number and a ‘-’
• Hence computer use three different techniques to denote signed binary numbers.
complement representation.
Sign-Magnitude Representation
• For signed binary numbers the most significant bit (MSB) is used as the sign
bit.
• The remaining bits in the number are used to represent the magnitude of the
binary number in the usual unsigned binary number format way.
• For instance, an 8-bit signed binary number 01100101 represents a
positive number whose magnitude is 1100101 2 = 101 10 .
• In the given number 01100101 MSB is 0, which indicates that the number
is positive.
• The 1 in the MSB position indicates that the given number is negative.
Convert the following decimal values into
8-bit signed binary numbers using the
sign-magnitude format:
• −15
100011112
Example
• +23
000101112
• -56
101110002
One’s Complement Representation
• Since positive numbers always start with a “0”, the complement will always start
with a “1” to indicate a negative number.
• Therefore, in the one’s complement representation the leftmost bit is 0 for positive
numbers and 1 for negative numbers, as it is for the signed magnitude representation.
• The process of changing 1’s to 0’s and changing 0’s to 1’s, is called as complementing
the bits.
• Thus the one’s complement of “1” is “0” and vice versa, then the one’s complement
of 100101002 is simply 011010112 as all the 1’s are changed to 0’s and the 0’s to 1’s.
Find the one’s compliment of binary
representation of decimal number −47
and +23?
• −47
Binary Value = 101111
Example Complement = 010000
One’s complement of −47 = 1010000
• +23
Binary Value = 010111
One’s complement of +23=010111
Two’s Complement Representation
• The subtraction of two positive numbers (M −N), both of base 2, can be done as follows:
(b) If in the end a carry does not occur, take the two’s complement of the number
obtained in step 1 and place a negative sign in front.
(a) Two’s complement of -10
Binary value of 10 = 1010
Complement of 101= 0101
One’s complement of -10 =10101
Two’s Complement of -10 = 10110
(b) Two’s complement of 11001111
Complement = 00110000
Two’s Complement = 110001
Using two’s compliment do the following
subtraction.
• 29−12
• 15−38
(a) 1101.01+101.01
(b) 110001.110−10111.010
Self-
Assessment (c) 110001.11×101.1
(e) 10111.110/1011.11
2. Give the representation of the following
negative numbers on a computer using two’s
compliment.
(a) −19710
(b) −198710
Self-
(c) −4932110
Assessment
3.Using two’s compliment do the following
Exercises
subtraction.
(a) 9457−6785
(b) 5830−876
THANK YOU