Chapter 5
Chapter 5
Chapter 5
Chapter 5
Computer Arithmetic
- computers are built from components that have two values; on/off
- the binary number system, which has only two digits 0 and 1 is used to express
the two states
- internal arithmetic operations of a digital computer are actually performed in
binary number system
= ∑ ai * 10i
i= -m
e.g.
- the decimal number 852.37 is equal to 8*102 +5 *101+ 2*100 +3*10-1 + 7*10-2
- Likewise, substituting any base in place of 10 will give the general form of a
number to that radix.
- In computer science 4 bases are of concerns: base 2, base 8, base 10 and base 16.
And the number systems in these bases are binary, octal, decimal and
hexadecimal respectively.
- Summary
Base Number System Possible Symbols(digits)
2 Binary 0 and 1
8 Octal 0-7
10 Decimal 0-9
16 Hexadecimal 0-9 and A-F
- Base n number has n possible digits and the digits are 0 to n-1
III. Conversion from One Base to Another
Step 1. Convert a given number to decimal number
Step 2. Convert the obtained no to the desired base
2. Repeat step 1 until a 0 quotient is obtained, using at each stage the quotient from
the previous stages as dividend
The successive remainders (starting from the least significant end) are the successive
digits of the number in base B
e.g convert
a) 67 to binary
b) 256 to binary
c) 256 to hexadecimal
Step 2 Explained:
To convert a decimal fraction to a fraction in base B
1. Multiply the given decimal fraction in base B
2. Repeat step 1 using the multiplicand at each step the remaining fractional part
from the previous step until a fractional part is identically 0, or until as many
digits as desired have been generated. The successive integral parts are the
successive digits of the number in base B starting from the most significant
end.
E.g convert
a) (.65)10 to binary
b) (.44)10 to quinary
c) (.32)10 to hexadecimal
Solution
.65 *2 = 1.3
.30 * 2 = .60
.60 * 2 = 1.20
.20 * 2 = .40
.40 * 2 = .80
.80 * 2 = 1.60
.60 * 2 = 1.20
.
.
. ____
Ans: (101001)
E.g Convert a) (256.65)10 to binary
b) (256.32)10 to hexadecimal
c) (10011.101)2 to quinary
Exercise
1. convert 192 to base 2
2. convert 192 to base 8
3. convert 192 to base 16
4. convert (100010101110.11011101)2 to decimal
5. convert (100010101110.11011101)2 to octal
6. convert (100010101110.11011101)2 to hexadecimal
7. convert (ABEBE)16 to decimal
8. convert (ABEBE)16 to binary
9. convert (ABEBE)16 to octal
10. convert( 256)2 to octal
- m is number of bits
- the excess of 2m-1 represents a number by storing it as the sum of itself and 2m-1
- e.g. for 5 bit number, the representation is called excess 16(25-1)
- -4 = -4 + 16 = 12 and -4 is represented by the 5 bit binary number for 12,i.e.
01100
- Exercise
- Represent -9 in:
a) Signed magnitude. Ans. 11001
b) Ones complement. Ans. 10110
c) Twos complement. Ans. 10111
d) Excess 16. Ans.00111
b) 6 00110 00110
-12 +10011 +10100
-6 11001 11010
N.B if the sign bits of A and B are the same but the sign of the result is different,
arithmetic overflow occurs. In case of “c” arithmetic overflow occurred.
=5 + 64 = 69 = (1000101)2
Thus, the representation of -18.375 is:
1 1000101 10010011000…0
---7 bits------- ----------16 bits----------
- If the mantissa has fewer digits than the required bit positions, zeros are added to
the end of the mantissa
- If the characteristic has fewer digits than the required bit positions, zeros are
added to the beginning of the characteristic
- Exercise
1. Perform the following operations in binary
a. 1101.01 + 11.11
b. 1101.01 * 11.11
2. Perform the following subtraction using twos complement in 6 bits
a. 111100 – 111011
b. 1101.010 – 11.1101
3. Repeat problem 2 using 1’s complement
4. convert 4.375 to normalized binary floating point form (7 bit exponent,
16 bit mantissa)
5. convert -4.350 to normalized binary floating point form (8 bit
exponent and 27 bit mantissa)