Professional Documents
Culture Documents
COMPUTER ARITHMETIC
Learning Objectives
In this chapter you will learn about
Reasons for using binary instead of decimal numbers
Basic arithmetic operations using binary numbers
Addition
Subtraction
Multiplication
Division
Complement of number
r’s complement ( radix complement )
(r – 1)’s complement (diminished radix complement)
Signed & Unsigned numbers
Binary Coded Decimal Operation
A. BINARY OVER DECIMAL
Information is handled in a computer by electronic/ electrical components
Electronic components operate in binary mode (can only indicate two states – on (1) or off (0)
Binary number system has only two digits ( 0 and 1 ), and suitable for expressing two
possible states
In binary system, computer circuits only have to handle two binary digits rather than ten
decimal digits causing:
Simpler internal circuit design
Less expensive more reliable circuits
More reliable circuits
Arithmetic rules/ processes possible with binary numbers
B. BASIC ARITHMETIC OPERATIONS
Binary Arithmetic is simple to learn as binary number system has only two digits 0 and 1
Example #1.Add binary numbers 10011 and 1001 in both decimal and binary form
Solution
Binary Decimal
Carry 11 Carry 1
1001 1 19
+ 100 1 + 9
111 00 28
In this example, carry are generated for first and second columns
Example #2. Add binary numbers 100111 and 11011 in both decimal and binary form
Solution:
Binary Decimal
The addition of three 1’s can be
broken up into two steps. First, we
Carry 1 1 1 1 1 Carry 1
add only two 1’s giving 10
100111 39
(1 + 1 = 10 ). The third 1 is now
+ 11011 + 27
added to the result to obtain 11 (a 1
100 0010 66
sum with a 1 carry).
0–0=0
0 – 1 = 1 with a borrow from the next column
1–0=1
1–1=0
Solution:
0 1 0 Borrow
10101
- 01110
00111
Solution:
1 Borrow
1111011.11
- 1010101.10
100110.01
Multiplication of binary is like the typical operation. Knowledge in binary addition is also needed for
this operation
Solution:
1 0 1 1 1 ← Multiplicand
x 1 1 0 1 ← Multiplier
1 0 1 1 1 ← partial product
0000 0
10111
+10111
100101 0 1 1 ← Final sum.
Example #1. Multiply 1010 and 1001
Solution:
1010 ← Multiplicand
x1001 ← Multiplier
1010 ← partial product
0000
0000
+1 0 1 0
1 011010 ← Final sum.
As in the decimal number system (or in any other number system), division by zero is
disregarded The computer deals with this problem by raising an error condition called ‘ divide by
zero ‘ error
Solution:
0101
110 100001 (Dividend)
110 - Divisor greater than 100, so put 0 in quotient
1000 - add digit from dividend to group used above
110 - subtraction is possible, so put 1 in quotient
100 - remainder from subtraction plus digit from dividend
110 - divisor greater, so put zero (0) in the quotient
1001 - add digit from dividend to group
110 - Subtraction possible, so put 1 in quotient
11 ---remainder
COMPLEMENT OF A NUMBER
Complement of a number binary can be obtained by transforming all its 0’s to 1’s and all its 1’s to 0’s
• Common use of complement: subtraction operation.
• Perform subtraction through the addition operation.
C.1.1(r-1)’s Complements
• (r-1)’s complement for a number N with n digits in base-r numbering system is defined as:
(rn -1 ) – N -------formula 1
• Notice that the 1’s complement of binary numbers is formed by changing 1’s to 0’s and 0’s to 1’s
C1.2(r’s complement)
[ (rn -1 ) – N ] + 1 -------formula 2
For n bit binary number, 1 bit is reserved for sign symbol. If the value of sign bit is 0, then the given
number will be positive, else if the value of sign bit is 1, then the given number will be negative.
Remaining (n-1) bits represent magnitude of the number. Since magnitude of number zero (0) is
always 0, so there can be two representation of number zero (0), positive (+0) and negative (-0),
which depends on value of sign bit. Hence these representations are ambiguous generally because of
two representation of number zero (0). Generally sign bit is a most significant bit (MSB) of
representation. The range of Sign-Magnitude form is from (2(n-1)-1) o (2(n-1)-1).
For example, range of 6 bit Sign-Magnitude form binary number is from (25-1) to (25-1) which is equal
from minimum value -31 (i.e., 1 11111) to maximum value +31 (i.e., 0 11111). And zero (0) has two
representation, -0 (i.e., 1 00000) and +0 (i.e., 0 00000).
Unsigned numbers don’t have any sign, these can contain only magnitude of the number. So,
representation of unsigned binary numbers are all positive numbers only. For example,
representation of positive decimal numbers are positive by default. We always assume that there is a
positive sign symbol in front of every number.
Since there is no sign bit in this unsigned binary number, so N bit binary number represent its
magnitude only. Zero (0) is also unsigned number. This representation has only one zero (0),
which is always positive. Every number in unsigned number representation has only one unique
binary equivalent form, so this is unambiguous representation technique. The range of unsigned
binary number is from 0 to (2n-1).
Simply convert it into Binary number, it contains only magnitude of the given number.
= (92)10
= (1x26+0x25+1x24+1x23+1x22+0x21+0x20)10
= (1011100)2
Example-2: Find range of 5 bit unsigned binary numbers. Also, find minimum and maximum value in
this range.
Since, range of unsigned binary number is from 0 to (2n-1). Therefore, range of 5 bit unsigned binary
number is from 0 to (25-1) which is equal from minimum value 0 (i.e., 00000) to maximum value 31
(i.e., 11111)
In this code each decimal digit is represented by a 4-bit binary number. BCD is a way to express each
of the decimal digits with a binary code. In the BCD, with four bits we can represent sixteen numbers
(0000 to 1111). But in BCD code only first ten of these are used (0000 to 1001). The remaining six
code combinations i.e. 1010 to 1111 are invalid in BCD.
DECIMAL 0 1 2 3 4 5 6 7 8 9
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
• Example: (4321)10
= 0100 0011 0010 0001
Example: 1 carry
27 0010 0111
+ 34 0011 0100
------ -----------------
61 0101 1011 ---- >9
+ 0110 ----+6
----------------
0110 0001 (61)
Example #2:
1 1 carry
59 0101 1001
+ 39 0011 1001
-------- ----------------
98 1001 0010
0110 (+6)
---------------
1001 1000 (98)
Chapter V
EXERCISE
1. Add binary numbers 10111 and 1011 in both decimal and binary form
2. Represent decimal number 79 in unsigned binary number.
3. Find the 2’s complement of 110100:
4. Find the 10’s complement of 3829:
5. Find the 9’s complement of 2784:
6. Find the 1’s complement of 1100101:
7. Add binary numbers 111111 and 10011 in both decimal and binary form
8. Subtract binary numbers 1010100 from 1111010
9. Multiply 10111 by 1101
10. Divide 100001 by 011