You are on page 1of 9

CHPTER V

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

B.1. Binary Arithmetic

Binary Arithmetic is simple to learn as binary number system has only two digits 0 and 1

Rule for binary addition are the following:


0+0=0
0+1=1
1+0=1
1 + 1 = 0 plus a carry of 1 to next column

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).

Hence, 1 + 1 + 1 = 1, plus a carry of


1 to the next higher column
B.2 Binary Subtraction

Rule for binary Subtraction are the following:

0–0=0
0 – 1 = 1 with a borrow from the next column
1–0=1
1–1=0

Example #1. Subtract binary numbers 011102 from 101012

Solution:
0 1 0 Borrow
10101
- 01110
00111

Example #2. Subtract binary numbers 1010101.10 from 1111011.11

Solution:
1 Borrow
1111011.11
- 1010101.10
100110.01

B.3 Binary Multiplication

Rule for binary Multiplication are the following:


0x0=0
0x1=0
1x0=0
1x1=1

Multiplication of binary is like the typical operation. Knowledge in binary addition is also needed for
this operation

Example #1. Multiply 10111 by 1101

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.

B.4 Binary Division

Rules for binary Multiplication are the following:


0 ÷ 0 = 0 divide by zero (0) error
0÷1=0
1 ÷ 0 = 0 divide by zero (0) error
1÷1=1
 Start from the left of the dividend
  Perform a series of subtractions in which the divisor is subtracted from the dividend
 If subtraction is possible, put 1 in the quotient and subtract the divisor from the corresponding
digits of dividend
  If subtraction is not possible (divisor is greater than remainder) record a 0 in the quotient
 Bring down the next digit to add to the remainder digits. Proceed as before in a manner similar
to long division

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

Example #1. Divide 1000012 by 1102

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.1Two types of complements for each baser system:


 r’s complement ( radix complement )
 (r-1)’s complement ( diminished radix complement)

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

• Example #1: Find the 9’s complement of 12389:

Solution: using the formula 1


= (105 -1 ) - 12389
= 99999 -12389 = 87610

• Example #2: Find the 9’s complement of 1234:

Solution: using the formula 1


= (104 -1) – 1234 = 9999 -1234
= 8765

Example #3: Find the 1’s complement of 1011001:


= (27 – 1 ) – 101 1001
= 111 1111 – 101 1001 = 010 0110

• Notice that the 1’s complement of binary numbers is formed by changing 1’s to 0’s and 0’s to 1’s

Example: 1’s complement of 0001111 is 1110000.

C1.2(r’s complement)

(r’s) complement for number N in base r with n digits is defined as rn – N


• Also, r’s complement= ( r-1)’s complement +1

[ (rn -1 ) – N ] + 1 -------formula 2

• Example #1: Find the 10’s complement of 2389:

Solution: using formula 2


=[( 104– 1 ) – 2389] + 1
=9999 - 2389 = 7610 + 1 = 761110
• Example #2: Find the 2’s complement of 10 1100:

Solution using formula 2


= [(26–1)–101100]+1
= 11 1111 - 10 1100 = 01 0011 + 1
= 0101002

C.2 Signed Binary Numbers


• 01001 can be considered unsigned binary = 9 or signed binary = +9
• But, 11001 can be considered unsigned binary = 25 or signed binary = -9
• Signed numbers uses 0 for “ + ” and 1 for “ – “ , this system is called Signed magnitude convention
• All negative numbers have 1 in leftmost bit
• Signed magnitude is mostly used in ordinary arithmetic.
• The 1’s complement is mostly used in logical operations.
• The 2’s complement is mostly used in computer arithmetic.

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).

C.3 Unsigned Binary Numbers:

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.

C.3.1 Representation of Unsigned Binary Numbers:

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).

Example-1: Represent decimal number 92 in unsigned binary number.

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

It’s 7 bit binary magnitude of the decimal number 92.

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)

D. BINARY CODE DECIMAL (BCD)

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

• Invalid digits: 1010, 1011,1100,1101,1110,and 1111.

D.1 Advantages of BCD Codes


 It is very similar to decimal system.
 We need to remember binary equivalent of decimal numbers 0 to 9 only. 

D.2 Disadvantages of BCD Codes


 The addition and subtraction of BCD have different rules. 
  The BCD arithmetic is little more complicated.
 BCD needs more number of bits than binary to represent the decimal number. So BCD is
less efficient than binary.

D.3 BCD Arithmetic Rules:

1. Add 2 BCD numbers using regular binary addition.


2. Check each nibble (4-bit), if result is greater than 9, then add 6 to it.
3. If there is a carry between 2 nibble or coming from 2th nibble add 6.
BCD Addition

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

You might also like