Blogger Templates

Saturday, 20 October 2012

Arithmetics For Computer Science


Arithmetics For Computer Science

1.Inroduction

            a. Number System Base
·         Decimal – base of 10
·         Binary – base of 2-consists of only two digits,1 and 0
·         Hexadecimal – base of 16

     The origins of number base are yet to be known. However, we are quite familiar with the decimal base number type. The reason is most probably because we have 10 fingers. Imagine we have only 2 fingers, we will count using 1 and 2 only. And mathematician might count using numbers 0 and 1 as in binary numbers. The same goes for hexadecimal. Imagine if we have 16 fingers, we create additional 5 numbers to make 16 digits in a hexadecimal numbers.

Written by Mohd. Safar ( B031210227)

2.Conversion

a. Number System Conversion

Decimal
Binary
Hexadecimal
0
0000
0
1
0001
1
2
0010
2
3
0011
3
4
0100
4
5
0101
5
6
0110
6
7
0111
7
8
1000
8
9
1001
9
10
1010
A
11
1011
B
12
1100
C
13
1101
D
14
1110
E
15
1111
F


b. Decimal to Binary - 





            
  e.     Binary to Hexadecimal – 11011 = 1B₁₆
           By taking the value of binary numbers in nibble form and converting them to hexadecimal number. The same goes for vice versa, every digit in hexadecimal number represents a binary number in nibble form.

        
 f. Decimal to hexadecimal - 1432₁₀ = 598₁₆

Written by Soo Pheng Kian (B031210015)

3. 2’s Complement

2’s Complement number- since there are also negative number that must be proceed by the microprocessor, the 2’s complement representation is used o determine the sign and magnitude number.

E.g.

Decimal
8 – bit binary numbers
Process
Notes
sign
Magnitude
11
0
00001011
Conversion decimal to binary
-2’s complement number must be in 8-bit form

0
11110100
Inversion 0 to 1, 1 to 0
-The MSB is important

0
11110101
Addition, add 1
-If MSB = 1, value is negative
-11
1
11110101
Hence,negative value of 11 by 2’s complement method
-If MSB = 0, value is positive.

Written by Andy Low Foo Hwa (B031210343)

4. Binary Number Operations

4.1. Number Operations (Binary)

a) Addition – Binary – the addition of binary numbers is done by adding two binary                                           numbers. The easiest way to remember binary addition                                                   is adding without getting digits other than 0 and 1.
e.g.      101 + 110 = 1011 , from the equation 1 + 1 means 10 instead of 2.



b.Subtraction-Binary
(i) the sub traction of two binary number is done similarly to the way we subtract two decimal numbers.The easiest way to remember binary subtraction is 0 cannot subtract 1.Therefore 0 needs to borrow a higher digit to become 10.Hence,10 can subtract 1.
Eg.   101₂-011₂=010₂                                        101
                                                                            - 011
                                                                              010

(ii) However,in microprocessor-based equipment,there is no subtraction.Therefore,there is another way to subtract which is using 2’s complement number.Important things to remember is a number binary number must be in the form of 8-bit and the MSB (most significant bit) can only have number 0 and 1.


Eg.    101₂-011₂=00000101₂-00000011₂                                     00000101₂
                           =00000101₂+(-00000011₂)                             + 11111101₂  
                           =00000101₂+(11111101₂)                                  00000010₂   
                           =00000010₂  ,is a negative number
If MSB is 0,its negative.
If MSB is 1,its positive.

c.Multiplication-Binary
Binary multiplication is basically the same as decimal multiplication with only two outcome,0 and 1.As we know 0 has no value, so when 1 is multiplied by 0 or 0 is multiplied with 1 or when 0 is multiplied by itself, you get 0.You only get the value 1 by multiplying 1 by itself. However ,the multiplication of long binary number does not end there.

Eg.      110₂x111₂=101010₂                                            110₂  →multiplicand
                                                                                  X       111₂   →multiplier
                                                                                         110
                                                                                       110
                                                                                        110                  
                                                                                      101010₂  →product

   Binary multiplication starts with multiplying a binary number which is called multiplicand with every digits in another binary number called the multiplier and sum of their outcomes is the value of the multiplication product.


d.Division-Binary
Binary division is following the same procedure as binary multiplication.

Eg.              110÷10=11₂                                                     ͟͟ ͟   ͟1͟ ͟1 ͟  
                                                                                        10  /  1 1 0
                                                                                              ͟  ͟ 1͟ ͟0͟  ͟  ͟   
                                                                                                    1 0
                                                                                                    ͟1͟ 0͟      
                                                                                                    0 0

Binary Division is as the same as the division of two decimal number.

Written by Mohd. Safar (B031210227)


5. Hexadecimal number operations


(a.)Addition-Hexadecimal

As in decimal numbers,if a sum of a number greater than 9,you get 10 which is two digit by bringing the value 1 to a digit after it.The same goes in hexadecimal.If a sum of two hexadecimal number is greater than

15₁₆,you get an additional digit after it which is 1.

Eg.   DF₁₆+AC₁₆=18B₁₆





(b.)Subtraction-Hexadecimal

The subtraction of hexadecimal number is done by converting the negative hexadecimal number to binary member and applying 2’s complement method and change it back to hexadecimal member.Than sum up both members.

Eg.      C3₁₆-0B₁₆=C3₁₆+F5₁₆                                                  -0B₁₆=00001011₂
                               =B8₁₆                             2’s complement method=11110101
                                                                                                                =F5₁₆
                                                                        C 3 ₁₆
                                                                     + F 5 ₁₆
                                                                       1 B 8 ₁₆   →since there is only 8 digits in
                                                                                            2’s complement number

(c)Since multiplication and division is a tedious and long process,the easiest way to conduct the operation is by changing the base to decimal or binary form. 

Written by Ng Wui Sheng (B031210031)

No comments:

Post a Comment