Menu
Log in

Computer Engineering Concepts

2.6 Fractions and Decimals

In the section on mathematical operations the need to represent parts of a number was encountered when we looked at division. In the decimal system a dot, which is commonly referred to as the decimal point, is used to indicate fractions or parts of a number. The use of the decimal helps to extend the representation of number beyond whole numbers (integer numbers) to numbers with parts (real numbers). In the decimal system a digit appearing after the dot represents a unit value that is one over an exponent of ten. For example,


Using the same concept parts of a number can be implemented in a different base where each digit after the dot represents a unit value that is one over an exponent of the base. For example, in base 2 or binary 


It is important to note that 0.1 in base ten is one tenth, and 0.1 in base two is a half. At this point the use of the term decimal point should be discontinued for other bases because the word decimal refers to one tenth but in base two the number after the dot represents a half. The proper mathematical term for this dot that is used to separate the whole number from the fractional part is the radix point. Here again the same symbolic description has two different numerical values. 0.1 means one tenth in the decimal base and one half in binary, therefore to avoid confusion the base subscript should be used to indicate the difference. This extension using the radix idea allows a real number (numbers with decimals) to be converted from one base to another. For example, to convert from a real number in binary to a real number in decimal the same conversion procedure is followed.

101.1012 = (1)22 + (0)21 + (1)20 + (1)2-1 + (0)2-2 + (1)2-3 = 4+1+0.5 +0.125 =5.625

To convert from a real number in decimal to a real number in binary or any other base the first method outlined earlier for conversion can be used. The division method does not work well in this case. If decimal 6.4 needs to be converted to binary, then using the first conversion method the following is obtained.

6.4 =   (1)22 + (1)21 + (0)20 + (0)2-1 + (1)2-2 + (1)2-3 = 110.0112

It should be noted that 6.4 is not exactly equal to 110.0112. To get better accuracy in the result, a few more places after the radix need to be determined. The examples outlined earlier have focused on binary fractions and decimals, but the concepts remain true for all bases. The emphasis on binary is mainly due to the fact that binary is the number system of choice for computer systems.


Rounding Off

In the decimal system the method of rounding off numbers is determined by the digit 5. For example consider rounding off of the number 8.3729 to two decimal places. To do this we look at the digit on the third decimal place. If the digit on the third decimal place is less than 5 then it is dropped, and if it is greater than or equal to 5 a 1 is added to the digit on the second decimal place. In this case if the number 8.3729 is rounded off to two decimal places, then becomes 8.37. If the number 8.3729 is rounded off to three decimal places it becomes 8.373.

To round off numbers in other bases the digit 5 cannot be used as the determining digit because it may not be the middle digit in that base. For example, if the number 123.10324 is to be rounded off to two digits after the radix point. The digit 5 will not help us solve the problem. Instead we need to look at the middle digit in the base, in this case the symbol 3 is the middle symbol of the symbol set. So any symbol after the middle is used for rounding up, and any symbol before the middle symbol is used for rounding down. Therefore, the number 123.10324 rounded to two places will be 123.114, and the number rounded to three places will be 123.1034. The rounding off process is easily transferred over from the decimal to all even bases, because a middle digit is easily identified. To round off numbers in odd bases the task is a bit more involved. In this case we look at two digits to decide on the rounding, instead of a single digit. For example, the number 41.131425 is in an odd base. The middle point will determined by the digits 23. If the digits are greater than 23 then it is rounded up and if it is less than 23 it is rounded down. The number 41.131425 rounded to one place will be 41.25 because the digits 31 is greater than 23, so it is rounded up. Similarly 41.131425 rounded to two places will be 41.135 because the digits 14 are less than 23, so it is rounded down.

Rounding of numbers in binary is easy because it is an even base. The midpoint in the binary symbols set is 1, so if the next digit is 1 it is rounded up and if it is 0 it is rounded down. The number 10101111.01110111 rounded off to different places is: 10101111.1 to 1 place and 10101111.01111 to 5 places. Rounding of numbers introduces errors in computations, therefore it is important to be aware of it.


Mathematical Functions

Other mathematical functions, like square root, sine, tangent, and log, can also be computed in binary. These values are computed using different algorithms. An algorithm is a sequence of steps that leads to the desired result. For example, consider the case of determining the square root of a number. The square root can be determined by using an algorithm that is similar to long division. Imagine that the square root of 352.6 needs to be determined. The following algorithm will help us determine the square root of a number using a systematic approach.

·     Group the digits into pairs on either side of the radix. E.g. 03 52 . 60 00 00

·     Determine the largest square that is present in the first pair. In this case 1.

·     Determine the difference between the largest square and the first pair. In this case 2.

·     Join the difference obtained in the step two with the second pair of numbers. In this case, it produces 252.

·     Multiply the square root developed thus far by 20. In this case 1x20=20

·     Determine the next digit in the square root by solving for the variable in the equation (20+) x d  ≤ 252

·     Steps 4, 5 and 6 are repeated until the desired accuracy is reached.


The accuracy of the square root is increased if the process is continued further. The value of sqrt(352.6) to five places is 18.77765. When the result obtained through this algorithm is compared to the actual value, the effectiveness of the algorithm is seen. If further accuracy is needed, then the algorithm could be repeated to achieve greater accuracy. This algorithm of finding the square root of a number can be converted to binary and used to determine the square root of any number.

The algorithm in binary is essentially the same, but with one slight modification. Instead of multiplying the digits of the square root by 20 it is multiplied by 4 or 1002. The algorithm in binary is a bit easier because the choice of digits for d is limited to two options, 1 or 0. The following example shows the same process in binary.

Example I:        Determine the square root of 11002 in binary.

Solution:


From the example it can be seen that it is possible to determine the square root of a number in binary. The validity of the results can be checked by converting it to decimal. The operation in decimal is =3.464, but our results in binary gives 11.010 which is 3.25. The difference is due to the number of places the square root was calculated to. If it is continued to the next digit, then the result would be 11.0101 which is 3.3125, a more accurate result.

Similarly other algorithms are used to determine the results of various mathematical functions. For example, if an angle is measured in radians, then the sine value of a number can be calculated using the following algorithm.


                  

The validity of these algorithms can be proven mathematically, but it can be quickly checked using a calculator.

The algorithms for the computation of various mathematical functions are developed based on proven mathematical relationships. These algorithms are used by the computer to determine the values of the different mathematical functions. The CPU within the computer essentially performs simple arithmetic in binary, so to evaluate complex mathematical functions, an algorithm based on arithmetic is need by the computer. When selecting an algorithm it is important to keep in mind the number of computations that are required to evaluate the function. If the number of steps are fewer and the type of computation simpler, then the algorithm will produce the result faster.


2.6 Practice Questions

1.     Convert the following decimal real number into binary real numbers.

        a. 1.25                b. 2.625                           c. 3.125                  d. 5.375                          

 2.    Convert the following real binary numbers into real decimal numbers.

         a. 11.101           b. 1.1101           c. 111.1011 d. 10.01111

 3.    What is the difference between the decimal point and the radix point?

 4.    Round off the number 10.0101101 to the following number of places.

        a. 1                       b. 2                     c. 3       d. 6                    

5.     Round off the following numbers to two places in the given base.

        a. 12.72478        b. 23.4136          c. 1.4325 d. 0.21113         

6.     Does rounding off of numbers in binary and decimal produce the same amount of error? Explain.

7.    Determine the square root of the following decimal numbers using the algorithm discussed in this section.

        a. 67                    b. 89                   c. 216                 d. 783                

8.    Determine the square root of the following binary numbers using the algorithm discussed in this section. Perform the algorithm in binary.

        a. 101                  b. 1101               c. 11001              d. 10011

9.    Use a calculator to verify that the algorithm for the sine function is valid for the following angles by calculating two terms in the algorithm.

       a. 0.2 rad             b. 1.2 rad           c. 15o    d. 20o               

10.   What happens to the accuracy of the sine values in question 9 if more terms of the algorithm are considered in the calculation?

11.        How might the value of cosine function be evaluated using the sine algorithm? 



GlobalEduTech Solutions

Powered by Wild Apricot Membership Software