# Computer Arithmetic

**Contents**

** **

**1.Number System and Data Representation**

Computer being an electronic device works on the presence or absence of electronic signals. Computer systems do not represent numeric values using the decimal system. Instead they typically use a binary or two's complement numbering system. The base of numbering system is called ‘Radix’.

It can just recognize two states either ON or OFF and numbers are represented by using these two states i.e., ON position represents‘1’ and the OFF position represent ‘0’. Therefore, any number can be represented easily by the computer under a number system which uses these two digits i.e., ‘0’ and ‘1’. This system is called Binary system.

**Decimal Number System:**

In this number system we use 10 digits from 0 to 9. Each decimal ‘digit’ takes one of these ten values. The value depends on the ‘position’ of the number system i.e., units, tens, hundreds and so on. The positional value of each digit has to be the power of 10. Therefore, the Radix of decimal system is 10.

Let’s understand this with an *Example*: Consider a number 354

This is also represented as (354)_{10}

354=3*10^{2 }+ 5*10^{1} + 4*10^{0}=300+50+4

**Binary Number system** or **base-2 number system: **

The binary digits (0 and 1) are used to represent data in a computer. In computer terminology, the binary digit is called as a ‘bit’. All the alphabets, numbers and symbols etc are represented in terms of 0s and 1s. The positional value of each digit has to be the power of 2. The radix of binary system is 2.So this is also called as ‘BASE2’ number system.

For converting binary to decimal, we should multiply place value of binary numbers with the number and add the result so to get the value in decimal system.

** Example:** Convert 10101

_{2 }to its equivalent decimal.

*Solution:*

2^{5} 2^{4} 2^{3} 2^{2} 2^{1} 2^{0} Place value

1 0 1 0 1 Binary number given in the example

10101_{2}=1*2^{4}+0*2^{3}+1*2^{2}+0*2^{1}+1*2^{0} =16+0+4+0+1=**21 _{10}**

**Octal Number System:**

In Octal number system the base is 8. Therefore, it is called as Base-8 number system. The eight symbols or digits are from 0 to 7.

** Example:** Convert Octal Number 2057 to decimal.

*Solution:*

(2057)_{ 8}= 2*8^{3}+0*8^{2}+5*8^{1}+7*8^{0} = 1024+0+40+7=1071_{10}

**Hexadecimal System:**

In this number system the base is 16.Hence 16 elements are used for its representation. The first 10 digits form from 0 to 9. The remaining six digits are denoted by symbols A, B, C, D, E, and F, representing 10, 11,12,13,14 and 15, respectively. Each position in hexadecimal number system represents a power of the *base (16).*

** Example:** Convert hexadecimal number 1AF to decimal.

*Solution:*

(1AF)_{ 16 }= 1*16^{2}+10*16^{1}+1*16^{0}

= (1*256) + (10*16) + (15*1) =256+160+15=431_{10}

**Converting from Decimal to another base:**

**Decimal to binary conversion:** The given decimal number is repeatedly divided by 2 (base of binary system) until it is no longer divisible. At the end of each of successive division, the remainder is written in the next column. The binary equivalent of given decimal number is obtained by writing the remainder from the bottom to the top starting from 1.

** Example:** Convert decimal 156 into its equivalent binary

*Solution:*

`2`

__)156__
Remainder

` 2`

__)78__ 0` 2`

__)39__ 0

` 2`

__)19__ 1

` 2`

__)9__ 1` 2`

__)4__ 1` 2`

__)2__ 0` 2`

__)1__ 0` 2`

__)0__ 1

Binary equivalent of 156_{10} = 10011100_{2}

**Note**: To convert Decimal to any base we should divide the decimal with that base. And the rest procedure is same as with decimal to binary conversion.

** Example:** Convert 428

_{10 }to hexadecimal.

*Solution:*

`16`

__)428__ Remainder

`16`

__)26__ 12=C`16`

__)1__ 10=A

`16`

__)0__ 1=1

` `

428_{10 }= 1AC_{16}

**Fractional Number:**

In binary number system, fractional numbers are formed similar as in decimal number system.

Example: 0.436_{10} = (4*10^{-1}) + (3*10^{-2}) + (6*10^{-3})

Similarly in binary number system,

0.657_{2} = (6*2^{-1}) + (5*2^{-2}) + (7*2^{-3})

** Example:** Convert Decimal equivalent of the binary number 110.101

** Solution:** 110.101

_{2 }= 1*2

^{2}+1*2

^{1}+0*2

^{0}+1*2

^{-1}+0*2

^{-2}+1*2

^{-3}

^{ } =4+2+0+0.5+0+0.125

=6.625

110.101_{2 } =6.625_{10}