Chapter 2
Chapter 2
Computer Arithmetic
Integer representation
Sign-magnitude representation
One’s complements
Two’s complements
Floating point representation
Booth algorithm
• Number systems include decimal, binary, octal and
hexadecimal
Number System Base Symbol
Binary Base 2 B
Octal Base 8 O
Decimal Base 10 D
Hexadecimal Base 16 H
2
Decimal Number System
• The number system that we use in our day-to-day life is the decimal
number system.
• Decimal number system has base 10 as it uses 10 digits from 0 to 9.
• In decimal number system, the successive positions to the left of the
decimal point represent units, tens, hundreds, thousands and so on.
• The weighted values for each position are:
10^4 10^3 10^2 10^1 10^0 10^-1 10^-2 10^-3
10/2 5 0 001101
5/2 2 1 1001101
2/2 1 0 01001101
1/2 0 1 101001101
10
Converting Binary to Octal
start
100011001010012
Step 1: Take the binary number and from right to
left, group all placeholders in triplets. Add leading
zeros, if necessary:
11
0010 001 100 101 0012 = 214518
13
Decimal-Octal:
4497810 to Octal
Repeated Division By 8
Division Quotient Remainder Binary
44978 / 8 5622 2 2
5622 / 8 702 6 62
702/8 87 6 662
87/8 10 7 7662
10/8 1 2 27662
1/8 0 1 127662
Decimal to hexadecimal
Convert 83010 to its hexadecimal equivalent:
830 / 16 = 51 R14
51 / 16 = 3 R3
3 / 16 = 0 R3
33E16
Convert Hex to Binary
• For each of the Hex digit write its binary
equivalent (use 4 bits to represent)
• Example
Convert 25A0 to binary
000100102 = 1810
100100102 = -1810
Sign bit Magnitude
Sign bit Magnitude
Left most bit is sign bit
0 means positive
1 means negative
+18 = 00010010
-18 = 10010010
One’s Complement Representation
• The one’s complement of a binary number involves inverting all
bits.
• To find negative of 1’s complement number take the 1’s
complement of whole number including the sign bit.
000011002 = 1210 111100112 = -1210
Sign bit Magnitude Sign bit 1’complement
• Two’s Complement Representation
• The two’s complement of a binary number involves inverting all
bits and adding 1.
• To find the negative of a signed number take the 2’s complement
of the positive number including the sign bit.
000011002 = 1210 111101002 = -1210
27
Subtraction of binary number system
Consider the subtraction of (-6) - (-13) = +7.
• In binary with eight bits this is written as 11111010 - 11110011.
• The subtraction is changed to addition by taking the 2’s
complement of the subtrahend (-13) to give (+13).
• In binary this is 11111010 + 00001101 = 100000111.
• Removing the end carry, we obtain the correct answer 00000111
(+ 7).
Division of binary number system
example 74 ÷ 8
1 0 0 1 Quotient
Divisor 1 0 0 0 1 0 0 1 0 1 0 Dividend
- 1 0 0 0
1 0
1 0 1
1 0 1 0
- 1 0 0 0
1 0 Remainder
29
Multiplication of binary number system
• The simplest machine multipliers are designed to follow a
variant of the pencil-and-paper multiplication algorithm:
…Example 8X9=72
Booth’s Algorithm
• The second method for binary multiplication
Is called Booth’s algorithm
• Possible arithmetic actions:
00 no arithmetic operation
01 add multiplicand to left half of product
10 subtract multiplicand from left half of product
11 no arithmetic operation
Example
• Therefore the answer is the combination of the A and Q column at
the fourth cycle which is 00010101