BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »
Showing posts with label Arithmetic for Computer Science. Show all posts
Showing posts with label Arithmetic for Computer Science. Show all posts

Sunday, 21 October 2012

Binary Division









by Wong Poh Ling B031210033

Wednesday, 17 October 2012

Binary Subtraction


0 – 0 = 0
1 – 0 = 1
0 – 1 = 1
*  Digit “0” will transform to digit “1”,while 1 is borrow from the left side.



One’s Complement Addition and Subtraction
*  N-bit represent integers in the range –(2N-1-1) to +(2N-1-1) or call modulo (2N-1-1)
Example of Number Presentation :
The table show that all possible value is in 4-bit system:

No.
Positive binary (+)
Negative binary(-)
0
0000
1111
1
0001
1110
2
0010
1101
3
0011
1100
4
0100
1011
5
0101
1010
6
0110
1001
7
0111
1000
8
1111
0000

Two’s Complement Addition and Subtraction
*  N-bit be defined as complement with respect to 2N
*  Equivalent taking one’s complement and then plus “1”
*  N-bit can represent in the range –(2N-1) to +(2N-1-1)
Example :


Signal overflow :
*  Different for unsigned and two’s complement representation.
*  Not necessarily occur when it carry out of sign, but occur when the result is of the opposite sign.
*  Two example of 8-bit for present the result of two’s complement addition.

-lee Man


Binary Addition


The simplest arithmetic operation in binary is addition.
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0

  Digit “1” will produces digit “0”,while 1 is carried to be next column.
For Example :







For example

        111111002

     25210
  +    000100102
              à
  + 11410
      1011011102

     36610


        000100112

      1910
  +    011001102
              à
  + 10210
        110001002

     19610

-Lee Man

the Hexadecimal System



Conversion of Hexadecimal to…
Decimal:
The hexadecimal can be converted to decimal by using the 16n system…
Eg:
C616
Hexadecimal            C                   6
Decimal              * 12×161            6×160      =    192   + 6    = 19810  
                      *   (C is equal to 12 in the Number System Conversion of  hexadecimal)
Eg 2 :
FFD4.F16
Hexadecimal            F               F                       D               4            .         F
Decimal               *15×163     15×162      **13×161      4×160            .     15×16-1
                            =61440 + 3840 + 208  + 4+0.9375
                            =65492.937510
(* 15 is equal to the  F in the Number System Conversion of hexadecimal…
  **13 is equal to the D in the Number System Conversion of hexadecimal…)

Binary:
The conversion of hexadecimal  to  binary  by 3 methods:
·         Converting to decimal and then to binary
·         According to the Number System Conversion between hexadecimal and binary
·         By using the 2n  system
Eg :
2C16
Method 1: Converting to decimal and then to binary
Hexadecimal                2                     C                 
Decimal                  2×161               12×160         =    32+ 12 =4410

 



Then convert the decimal into binary by using division…
2
44
2
22          0
2
11          0
2
  5          1
2
  2          1

  1          0
                                                               
4410 = 1011002
And also can written as …
2C16  =   1011002

Method 2 : According to the Number System Conversion between hexadecimal and binary
Hexadecimal         2                 C
Binary               0010              1100
·         2C16  =    10 11002
Method 3: By using the 2n system
---when  converting the binary into hexadecimal ,we need to group the binary into 4…and the 4 of grouped binary are indicated by the 2n system…
For example,   the most left of the  grouped binary indicate the 23,next is 22 , followed by 21, and lastly is 20
So,
2C16 =  0010 11002
(00102 = ( 0×23)+(0×22)+(1×21)+(0×20)=0+0+2+0=216;
1100=(1×23) + (1×22) + (0×21) + (0×20) = 8+4+0+0= 12=C16)

Eg 2:
C6.F16
We convert according the Number System Conversion between the hexadecimal and binary…

Hexadecimal                 C                     6               .                F
Binary                      1100                 0110                         1111
So,
C6.F16 =  1100 0110.11112

Octal:
There are few ways to convert the hexadecimal to octal:
·         Convert the hexadecimal into decimal and then to octal
·         Convert the hexadecimal into binary and then to octal
Eg :
4A16
Method 1: Convert the hexadecimal into decimal and then to octal
Hexadecimal          4                     A
Decimal               4×161            10×160   =    64 + 10 =7410

Convert to octal by dividing the decimal with 8…
          8
           74
          8
             9              2

             1              1
                                                                                            
4A16  = 1128
Method 2 : Convert the hexadecimal into binary and then to octal
Hexadecimal                    4                              A
Binary                       *   0100                      **1010
                           * ((0×23) + (1×22) + (0×21) + (0×20) =416)
                         **((1×23) + (0×22) + (1×21) + (0×20) = 10 =A16)
4A16 = 100 10102
Convert to octal by grouping the binary into 3…
100 10102  =  001 |  001 | 0102
Then , according to the Number System Conversion between Octal and binary…
Octal
Binary
0
000
1
001
2
010
3
011
4
100
5
101
6
110
7
111

10010102 = 1128
Or …
By using the 2n system…
100 10102 =     001    |     001    | 0102
                    =((0×22)+(0×21)+(1×20)) |((0×22)+(0×21)+(1×20)) | ((0×22)+(1×21)+(0×20))
                    =1             |        1      |    28
Therefore ,
4A16  =   1128

Eg 2 :
6A.B16
Converting to binary …
Hexadecimal            6                 A         .             B
Binary                   0110            1010     .          1011
6A.B16 = 1101010.10112
Converting into octal…
1101010.10112 =   001 |101 |010. |101 | 100  
(According to the Number System Conversion between octal and binary)
                             =     1 |    5   | 2  .   |   5   |48

Therefore,
6A.B16  =    152.548

by Chong Cai Ning B031210080 shinbachi123@hotmail.com

Multiplication








-Wong Poh Ling

Tuesday, 16 October 2012

the Octal System


For this section, let’s take (65)8 for example.

Conversion of Octal to Decimal
Octal Number
6
5
Significance of each bit
81
80
Weighted value
6(8) = 40
5(1) = 5
Solved Multiplication
48
5

Therefore = (65)8 = 48 + 5 = 53

Conversion of Octal fraction to decimal fraction
Take (0.5)8 for an example.
Octal number
5
Significance of bit
8-1
Weighted value
5(8-1)
Solved multiplication
0.625

Therefore, (0.5)8 = 0.625, and (65.5)8 = 53.625

Conversion of Octal to Binary
When converting octal to binary, we follow these steps:
1.       Convert each octal digit to its 3-bit equivalent.
2.                    Combine the numbers

(65)8
Octal number
6
5
Binary number
110
101

Combine them: 1101012
8-bit binary number = 001101012

Conversion of octal fraction to binary fraction
0.58
Octal number
5
Binary number
101

Therefore (0.5)8 = 0.101 and (65.5)8 = (110101.101)2


-Xin Lin

the Binary System


Conversion of binary to ….
Decimal:

The steps to convert the binary numbers to the decimal:

  • ·        Use the bit of binary number one-by-one (starting with the most significant (leftmost) bit. Begin with the value 0
  • ·         Then , repeatedly double the prior value
  • ·         Add the next bit to produce the next value
  • ·         The next value is taken down as the prior value and multiply the 2 and also add the next bit.
  •         Eg:  102
  •     (0×2)+1=1(  1  = this  value is then taken down to multiply 2 and adding the second bit,0 )
  •     (1×2)+0=2
  •       The operation is repeated until the last bit
Eg:
Prior value




×2and +
Next bit
Next value
0
1
1
1
0
2
2
1
5
5
1
11
11
0
22
22
1
45
45
0
90

1011010=  90 10
Step 2:
Binary        1         0         1          1         0          1          0
Decimal   1×26   0×25   1×2   1×23    0×22    1×21    0×20   = 90

Eg 2:
Step 1:

11111012

Prior value





×2 and+
Next bit
Next value
0
1
1
1
1
3
3
1
7
7
1
15
15
1
31
31
0
62
62
1
125
    
11111012  = 125 10
Step 2:
Binary         1          1          1          1           1          0           1
Decimal    1×26   1×25    1×2   1×23      1×22     0×21     1×20    =125


:The  conversion of binary fraction  to decimal fraction=

Eg :
0.110102
Weight
...20
2-1
    2-2
    2-3
      2-4
      2-5
   
Value represented
… 1
 0.5
   0.25
    0.125
   0.0625
 0.03125
Binary
…0
1
      1
      0
      1
      0

Converting the binary fraction to decimal fraction:
Binary           1             1            0           1           0
Decimal     1×2-1      1×2-2      0×2-3    1×2-4     0×2-5
=0.5 +  0.25  + 0.0625
=0.8125 10
:: therefore , 0.110102   =   0.8125 10

Eg:
0.112
Weight
…20
     2-1
     2-2
     2-3
Value represented
…1
   0.5
   0.25
   0.125
Binary
…0
      1
     1
      0

Converting binary fraction to decimal fraction=
Binary            1                1
Decimal      1×2-1        1×2-2    =    0.5 + 0.25  =  0.75  10
:: therefore,    0.11 =    0.7510


Hexadecimal:

The following below is the Number System Conversion between hexadecimal and binary:
Hexadecimal
Binary
0

0000

1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
A
1010
B
1011
C
1100
D
1101
E
1110
F
1111


To convert binary to hexadecimal:
·        

  •       Grouped  the binary into 4
        For example :   1100 00112 =  1100   |   00112

  • ·         If the binary not enough to group into 4, then insert an extra 0 bit  on the left side of binary (called padding )
         For example :   11000112  =   0110    |   00112    (0 is the extra 0 bits inserted )

  • ·         After grouping the binary ,  according the Number System Conversion ,convert the binary into hexadecimal

Eg :
1100 00112
First step :Grouping the binary into 4
1100 00112   =  1100    |   00112
Second step : According to the Number System Conversion…
1100 00112  =  C316

Eg 2:
1011002
First step : Grouping the binary into 4
                     Since 1011002  is not enough to divide into 4 each ,therefore insert two extra
                     0 bits on the left side of binary.
1011002 =    0010   |  11002Second step :According to the Number System Conversion…
1011002 =3C16


Eg 3:
1011.112
First step :  Grouping the binary into 4
                     Since 0.112 is a decimal point therefore insert 2 0 bits on the right side of the
                     decimal point…
1011 .112 = 1011. |11002
Second step : According to the Number System Conversion between hexadecimal and       
                         the binary…

1011.112 =B.  C16


Octal:
It is easy to convert the binary into octal numeral system.
The steps to convert the binary into octal numeral system are:

  • ·         Grouping the binary into 3 each
         For example: 1100112   =   110   |    0112

  • ·         Likes the hexadecimal , if there isn't enough  to group the binary into 3,then insert an extra 0 bit on the left side of the binary . This process is called padding.
        For example: 100112   =    010   |  0112 ( 0 is the extra 0 bit inserted)

  • ·         Then according to the table as below:

        Number System conversion between octal and binary:

Octal
Binary
0
000
1
001
2
010
3
011
4
100
5
101
6
110
7
111


Eg:
110 0112

1.       Grouping the binary into 3:

110 0112   =    110 | 0112
2.       According to the table above:

110  =  6 ;    011  = 3;
 So, 110 0112  =  638
        

 Apart of that , there is also a way to convert binary to octal :


Eg 2:
1.       Grouping the binary into 3 :

110 0112  =   110   |   0112
2.       Convert the binary by using 2n system:

110 = (1×22) + (1×21) + (0 ×20)          |       011= (0×22) + (1×21) + (1×20)
        =4+2+0                                          |              = 0 + 2 + 1
        =6                                                   |            =3

Therefore,

110 0112 = 638


 Eg 3:
                 10 0112
1.       Grouping the binary into 3… but this binary is not enough to group into 3 so we have to insert an extra 0 bit at the left side of this binary…

10 0112    =   010  | 0112 ( 0 is the extra 0 bit inserted )
2.       Then, convert the binary into octal either according to the Number System Conversion between octal and binary or by using the 2n system…

Method 1: According to Number System Conversion between octal and binary
010 = 2               |        011 =3
Therefore,
10 0112   =   238

Method 2 :By using 2n system           |

010 = (0×22) + ( 1×21) + (0×20)           |       011= ( 0×22) + (1×21) + (1×20)
        =2                                                   |               =2+1
                                                                                                         =3
                        10 0112 = 238

Eg 4:
                   100011.112
                   1. Grouping the binary into 3…
                        100011.112 = 100 | 011. |1102
                   2.By using 2n system
           100=  (1×22) + (0×21) + (0×20)  | 011=(0×22) +(1×21) +(1×20) .| 110= (1×22)+(1×21)+(0×20)  
                 = 4 +0 +0                               |        =0 + 2 +1                            |        =4 + 2 +0
                 = 4                                         |         = 3                                       |       =6
                  100011.112  =  43 .6 8

-Cai Ning