Next: Computer representation of numbers... Up: Main Previous: Approximation and Round-off-Errors

Computer Representation of Numbers and Computer Arithmetic

In a Computer numbers are represented by binary digits 0 and 1. Computers employ binary arithmetic for performing operations on numbers. Since it gets cumbersome to display large numbers in binary form computers usually display them in hexadecimal or octal or decimal system. All of these number systems are positional systems. In a positional system a number is represented by a set of symbols. Each of these symbols denote a particular value depending on its position. The number of symbols used in a positional system depends on its 'base'. Let us now discuss about various positional number systems:

Decimal System:

The decimal system uses 10 as its base value and employs ten symbols 0 to 9 in representing numbers. Let us consider a decimal number 7402 consisting of four symbols 7,4,0,2. In terms of base 10 it can be expressed as follows.

$\displaystyle 7402=7\times10^{3}+4\times10^{2}+0\times10^{1}+2\times10^{0}$

So each of the symbols from a set of symbols denoting a number is multiplied with power of the base (10) depending on its position counted from the right. The count always begins with 0.

In general a decimal number $ d_{m}d_{m-1}...d_{1}d_{0}$ consisting of $ (m+1)$ symbols can be expressed as:

$\displaystyle d_{m}\times10^{m}+d_{m-1}\times10^{m-1}+....+d_{1}\times10^{1}+d_{0}\times10^{0}=\sum\limits_{i=0}^{m}
d_{i}10^{i}
$

where, $ 0\leq d_{i}\leq 9, \quad i=0,1,...m$

Similarly, a fractional part of a decimal number can be expressed as $ \sum\limits_{i=1}^{m}d_{i}10^{-i}$

Binary system:

Binary system is the positional system consisting of two symbols i.e. 0,1 and '2' as its base. Any binary number $ d_{m}d_{m-1}...d_{1}d_{0}$ actually represents a decimal value given by

$\displaystyle d_{m}2^{m}+d_{m-1}2^{m-1}+...+d_{0}2^{0}=\sum\limits_{i=0}^{m}
d_{i}2^{i}
$

where $ d_{i}=0\quad or\quad 1, \quad i=0,1,..m. $

Consider the binary number 10101. The decimal equivalent of 10101 is given by

$\displaystyle (10101)_{2}$ $\displaystyle =$ $\displaystyle 1\times 2^{4}+0\times 2^{3}+1\times
2^{2}+0\times 2^{1}+1\times 2^{0}$  
  $\displaystyle =$ $\displaystyle 16+0+4+0+1=(21)_{10}$  

Hexadecimal System:

The Hexadecimal system is the positional system consisting of sixteen symbols, 0,1,2...9,A,B,C,D,E,F, and '16' as its base. Here the symbols A denotes 10, B denotes 11 and so on. The decimal equivalent of the given hexadecimal number $ d_{m} d_{m-1}...d_{0}$ is given by $ \sum\limits_{i=0}^{m} d_{i}\times(16)^{i}$. For example consider $ (15ACB)_{16}$

$ (15ACB)_{16}=1\times 16^{4}+5\times 16^{3}+10\times 16^{2}+12\times 16^{1}+11\times 16^{0}$.

$ \qquad\qquad\qquad=65536+5\times4096+10\times256+12\times16+11\times1$

$ \qquad\qquad\qquad=65536+20480+2560+192+11 $ $ \qquad\qquad\qquad =(88779)_{10}$

We can convert a binary number directly to a hexadecimal number by grouping the binary digits, starting from the right, into sets of four and converting each group to its equivalent hexadecimal digit. If in such a grouping the last set falls short of four binary digits then do the obvious thing of prefixing it with adequate number of binary digit '0'. For example let us find the hexadecimal equivalent of $ (111\quad011\quad0101\quad0010\quad1110)_{2}$

$ (\underline{0011}\quad\underline{1011}\quad\underline{0101}\quad\underline{0010}\quad\underline{1110})_{2}=(3B52E)_{16}$

The vice-versa is also true.

Octal System: The octal system is the positional system that uses 8 as its base and $ \{0,1,...7\}$ as its symbol set of size 8. The decimal equivalent of an octal number $ (d_{m}d_{m-1}...d_{0})_{8}$ is given by $ (\sum\limits_{i=0}^{m}
d_{i}8^{i})_{10}$. For

example consider $ (6741)_{8},$

$ (6741)_{8} =6\times 8^{3}+7\times 8^{2}+4\times 8^{1}+1\times
8^{0}$

$ \qquad\qquad=6\times 512+7\times 64+4\times 8+1$

$ \qquad\qquad=3072+448+32+1$

$ \qquad\qquad=(3553)_{10}$

We can get the octal equivalent of a binary number by grouping the binary digits, starting from the right, into sets of three binary digits and converting each of these sets to its octal equivalent. If such a grouping results in a last set having less number of digits it may be prefixed with adequate number of binary digit 0. As an example the octal equivalent of $ (1010\quad110\quad111\quad001)_{2}=(001\quad010\quad110\quad111\quad
001)_{2}$

$ =(12671)_{8}$

Conversion of decimal system to non-decimal system:

To convert a decimal number to a number of any other system we should consider the integer and fractional parts separately and follow the following procedure:

Conversion of integer part:

(a) Consider the integer part of a given decimal number and divide it by the base b of the new number system. The remainder will constitute the rightmost digit of the integer part of the new number.

(b) Next divide the quotient again by the base b. The remainder will constitute second digit from the right in the new system.

Continue this process until we end up with a zero-quotient. The last remainder is the leftmost digit of the new number.

Conversion of fractional part:

(a) Consider the fractional part of the given decimal number and multiply it with the base b of the new system. The integral part of the product constitutes the leftmost digit of the fractional part in the new system.

(b) Now again multiply the fractional part resulting in step (a) by the base b of the new system. The integral part of the resultant product is the second digit from the left in the new system.

Repeat the above step until we encounter a zero-fractional part or a duplicate fractional part. The integer part of this last product will be the rightmost digit of the fractional part of the new number.

Eg: Convert 54.45 into its binary equivalent.

(a) Consider the integer part i.e. 54 and apply the steps listed under conversion of integer part i.e.

(b) Conversion of fractional part:

    Product integral part Binary number
0.45 $ \times$ 2 = 0.90 0 $ (.01\overline{1100})_2$
0.9 $ \times$ 2 = 1.80 1  
0.8 $ \times$ 2 = 1.6 1  
0.6 $ \times$ 2 = 1.2 1  
0.2 $ \times$ 2 = 0.4 0  
0.4 $ \times$ 2 = 0.8 0  
0.8 $ \times$ 2 = 1.6 1  
0.6 $ \times$ 2 = 1.2 1  
0.2 $ \times$ 2 = 0.4 0  
0.4 $ \times$ 2 = 0.8 0  
0.8 $ \times$ 2 = 1.6 1  
   
   

% latex2html id marker 542
$ \therefore(0.45)_{10}=(.01\overline{1100})_{2}$

% latex2html id marker 544
$ \therefore(54.45)_{10}=(110110.01\overline{1100})_{2}$

Here the overbar denotes the repetition of the binary digits.

Note: Using binary system as an intermediate stage we can easily convert octal numbers to hexadecimal numbers and vice-versa.

$ Eg:(a)(423)_{8}=(100\quad 010\quad 011)_{2}$

$ \qquad\qquad\qquad=(0001\quad 0001\quad 0011)_{2}=(113)_{16}$

In the above two examples we have grouped the binary digits suitably either to quadruplets or triplets to convert octal to hexadecimal and hexadecimal to octal numbers respectively.

Next: Computer representation of numbers... Up: Main Previous: Approximation and Round-off-Errors