Minggu, 18 April 2010

bin juml

CHAPTER 2 : COMPUTER REPRESENTATION AND
ARITHMETIC

2.1 : Representing Numbers In a Computer
2.2 : Representing Integers
2.3 : Arithmetic With Integers
2.4 : Representing Real Numbers
2.5 : Arithmetic With Real Numbers
2.6 : Binary Coded Decimal Representation

2.1 : REPRESENTING NUMBERS IN A COMPUTER

 In this chapter , we shall use the techniques we developed in Chapter 1 to investigate the ways in which numbers are represented and manipulated in binary form in a computer .

 Numbers are usually represented in a digital computer as sequences of bits of a fixed length .

 Integers and real numbers are handled in different ways . So we need to deal with the two cases separately .


2.2 : REPRESENTING INTEGERS

2’s Complement

 We use sign ‘ + ‘ and sign ‘ – ‘ to denote positive and negative numbers but the computer can process data only in term of bit .

 Computers store negative numbers in terms of their two’s complement .

 Ones Complement
Ones complement of a binary number A is obtained by interchange digit 0 with 1 and 1 with 0 .

 Examples :
Binary number : 11110011 110110011
Ones complement : 00001100 001001100

 Two’s Complement
Two’s complement of a binary number A is its ones complement PLUS 1 .


 Examples :
Binary number : 11110011 110110011
Ones complement : 00001100 001001100
+ 1 + 1
Two’s complement : 00001101 001001101

 A negative number will be store in its two complement in the computer .
( Example : -63 is store as 11000001 in 8-bits word computer system .)

-6310 = - ( 1111112 )

6310 in 8-bits word = 00111111

Ones complement = 11000000
+ 1
Two’s complement = 11000001
-63 = 11000012

 The range of number that can be stored in n – bit computer word in 2’s complement format is –(2n-1) to (2n-1-1) .

Example 1 :
Find the 16-bit computer representations of the following integers in 2’s complement :
( a ) - 205 ( b ) –15728 ( c ) –4961
Solution :




















Example 2 :
Find out the denary value for storage number 1100010110112 that using 2’s complement method in 12-bit system .
Solution :













2.3 : ARITHMETIC WITH INTEGERS

 Computer can only perform additions , so the performing of subtractions can be done by complement additions .

2’s Complement Subtraction

 To evaluate Y = B – A , we actually find Y = B + ( - A ) .

 Thus , in computer storage , to find B – A , we add B with the
2’s complement of A .


Steps In 2’s Complement Subtraction
1. Find the two’s complement of the second number , A .
2. add the 2’s complement of A to the first number B .
3. If the sum is more than the defined digit for A and B with the first digit equal to 1 , the final answer is the sum without the first digit 1 .
4. If the sum is the same digit as A and B , the final answer is the 2’s complement of the sum with a negative sign .






Example 1 :
Show how 165 – 89 can be evaluated in a 10-bit register using 2’s complement method. Justify your answer.
Solution :
















Example 2:
If numbers are held in 8-bit register in two’s complement, show how 75 – 110 is evaluated. Justify your answer.
Solution:






















Example 3:
Using two’s complement, base 10 integers are to be stored in 10–bits register.
(i) What range of integers (expressed in denary form), can be stored?
(ii) Show how 17110 is represented.
(iii) Show how – 18310 is represented.
(iv) Show how 17110 – 18310 would be evaluated.
Solution:







































Example 4:
A ten bits register is used to store integers using twos complement format.
(i) What range of integers (expressed in denary form), can be stored?
(ii) Show how (– 156 – 249) can be evaluated in this form.
Solution:









































2.4 : REPRESENTING REAL NUMBERS

 Before the computer representation of a real number can be found , the number must first be converted to binary form and then be expressed in normalized binary exponential form .

 A real number is expressed in normalized binary exponential form if it is expressed in the form :
+ m x 2e
where the significand m is written in its binary representation and lies in the range
0.12  m < 12 , and the exponent e is an integer written in its decimal representation .

Example 1 :
Express the following numbers in normalized binary exponential form :
( a ) 11001.1012 ( b ) 0.0001101112
Solution :









 A real number is typically stored in a computer as 4 bytes ( 32 bits ) or 8 bytes (64 bits). The first bit is the sign bit , and the remaining bits are divided between the exponent and the significand .

 A common format in modern computers is 8 bits for the exponent and 23 bits for the significand .

 It is usually not the binary representation of the exponent itself that is stored , but a number called the characteristic .

characteristic = exponent + exponent bias
= exponent + 2n – 1 –1 ( where n is the number of bits
available to store the characteristic )

 The first bit of the significand is not stored .





 Putting together what we have established , the process for finding the computer representation of a real number can be described as follows :

1 ) Convert the number to binary form , working to the precision required by the number
of bits used for the significand .

2 ) Express the binary number in normalized binary exponential form .

3 ) Calculate the characteristic .

4 ) Write down the computer representation .


Example 2:
Find the 24-bit computer representation of 25.828125, where 8 bits are used for the characteristic, and the exponent bias is 27 – 1.
Solution:





























Example 3:
Find the 32-bit computer representation of -1583.42, where 8 bits are used for the characteristic, and the exponent bias is .
Solution:


















Example 4:
Find the 32-bit computer representation of -2187.0625, where 8 bits are used for the characteristic, and the exponent bias is .
Solution:




















2.5 : ARITHMETIC WITH REAL NUMBERS

 We will not look at how a computer does arithmetic with real numbers using their computer representation .
However , we can gain a general idea of what the process involves by looking at how arithmetic is done with decimal numbers in normalized exponential form .

 The rules for arithmetic in normalized exponential form are as follows .

 To add or subtract :

1 ) Write the numbers in ( non-normalised ) exponential form with the same
exponent , using significands less than 1 .

2 ) Add or subtract the significands to obtain the significand of the answer. The
common exponent is the exponent of the answer .

3 ) Normalised the answer if necessary .

 To multiply or divide :

1 ) Multiply or divide the significands to obtain the significand of the answer .

2 ) Add or subtract the exponents to obtain the exponent of the answer .

3 ) Normalised the answer if necessary .




















Example 4 :
Perform the following computations with the aid of a calculator , assuming a precision of four decimal places in the significand :
(a) 0.4932 x 103 + 0.2881 x 104 – 0.3096 x 104
(b) 0.8463 x 107 + 0.7012 x 108 – 0.3315 x 106
(c) (0.2174 x 10-5) x (0.1482 x 107)  (0.9497 x 104)
(d) (0.9637 x 104) x (0.4576 x 103) + (0.7123 x 107)
Solution :






















2.6 : BINARY CODED DECIMAL REPRESENTATION ( BCD )

 The BCD representation of non-negative integer is obtained by replacing each decimal digit by its BCD code which require 4 bits for each decimal digit .

Decimal Digits BCD code
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Example 1 :
Encode the decimal number 469 using the BCD code .
Solution :




Example 2 :
Encode 83019 in BCD.
Solution :




Example 3 :
Decode each numeric, expressed in the BCD code :
( a ) 0111 0011 0000 1001 ( b ) 0101 1000 0010
Solution :





 Any two BCD codes can be added using the rules of binary addition to give the BCD code of the result , provided that result is less than 10 .

 If the result is 10 or more , add six ( 01102 ) and disregard the leftmost 1 .
( applying the rule is equivalent to subtracting ten , because disregarding the leftmost 1 is equivalent to subtracting sixteen ( 100002 )) .

Example 4:
Calculate 5498 + 5419 in BCD.
Solution:













Example 5:
Calculate 2039 + 978 in BCD arithmetic.
Solution:














Example 6:
Calculate 73613 + 437 in BCD.
Solution: