Sunday 7 October 2012

Chapter 2 Number Operation

Number Operation
Number operation(Arithmetic) is an operation describe what we need to do to numbers. There are four main operations which are addition(+), subtraction(-), multiplication(*) and division(/). 
Here, we will only focusing on binary and hexadecimal number system operations.

Binary number operation(Binary Arithmetic)
Addition 
Addition is the simplest number operation in binary number system.
Rule of binary addition,
0+0=0
0+1=1
1+0=1
1+1=0,and carries 1 to the next significant bit(most significant bit).
Note: The rules of the binary addition(without carries) are the same as the truth table of XOR gate.

Example for binary addition:
00010110+00001011

      1111   << carries
  00010110 =    22(base 10)
+00001011 =    11(base 10)
  00100001 =    33(base 10)


Subtraction
Rule of binary subtraction,
0-0=0
0-1=1,and borrow 1 from the next significant bit(most significant bit).
1-0=1
1-1=0

Example for binary subtraction:
01000100-00100010

    02     02   << borrows
  01000100 =    68(base 10
 -00100010 =   -34(base 10)
  00100010 =    34(base 10)

Subtracting a positive value are equivalent to adding a negative number which can represent by two's complement.

Multiplication
Multiplication in binary is similar to its decimal counterpart.
Rule of binary multiplication,
0x0=0
0x1=0
1x0=0
1x1=1,and no carry or borrow bits.

Let's 00101001 be A and 00000011 be B,
The number of A and B can be multiplied by partial products. For each digit in B, the product of A is calculated and written on a new line, shifted leftward so that its rightmost digit lines up with the digit in B that was used.
Since there are only two digits in binary, so there are only two possible outcomes of each partial multiplication:
1.If the digit of B is 0, then the partial product is 0.
2.If the digit of B is 1, then the partial product is A.
To get the final result of multiplication, you need to sum all of the partial product.


Example for binary multiplication,
00101001 x 00000101

    00101001 =   41(base 10)
  x00000101 =     5(base 10)
      1               carries
    00101001
  00000000
00101001             
    11001101 = 205(base 10)

Division
Division in binary is similar to its decimal counterpart.
01001100 / 00000100

           10011 = 19(base 10)
100|01001100 = 76/4(base 10)
        100
             110
             100
               100
               100


Hexadecimal number operation
Addition
In hexadecimal addition, the value will be carry into the next digit when the value exceed 1516.
Example,
AE86 + F3B6

  111           carries
    AE86 =   44678(base 10)
+  F3B6 =   62390(base 10)
  1A23C = 107068(base 10)

Subtraction
In hexadecimal subtraction, the value will be borrow from the most significant bit when then subtrahend value is bigger than minuend value.
Example,
F3B6 - AE86

    16         borrows
  F3B6 = 62390(base 10)
 -AE86 = 44678(base 10)
   4530 = 17712(base 10)

Multiplication
X
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
1
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
2
2
4
6
8
A
C
E
10
12
14
16
18
1A
1C
1E
3
3
6
9
C
F
12
15
18
1B
1E
21
24
27
2A
2D
4
4
8
C
10
14
18
1C
20
24
28
2C
30
34
38
3C
5
5
A
F
14
19
1E
23
28
2D
32
37
3C
41
46
4B
6
6
C
12
18
1E
24
2A
30
36
3C
42
48
4E
54
5A
7
7
E
15
1C
23
2A
31
38
3F
46
4D
54
5B
62
69
8
8
10
18
20
28
30
38
40
48
50
58
60
68
70
78
9
9
12
1B
24
2D
36
3F
48
51
5A
63
6C
75
7E
87
A
A
14
1E
28
32
3C
46
50
5A
64
6E
78
82
8C
96
B
B
16
21
2C
37
42
4D
58
63
6E
79
84
8F
9A
A5
C
C
18
24
30
3C
48
54
60
6C
78
84
90
9C
A8
B4
D
D
1A
27
34
41
4E
5B
68
75
82
8F
9C
A9
B6
C3
E
E
1C
2A
38
46
54
62
70
7E
8C
9A
A8
B6
C4
D2
F
F
1E
2D
3C
4B
5A
69
78
87
96
A5
B4
C3
D2
E1

Multiplication Table
Hexadecimal multiplication is similar to decimal multiplication.
Example,
8AC x 9A

  8AC  =  2220(base 10)
x   1A  =     26(base 10)
11     carries
56B8
8AC              
E178  =57720(base 10)

Division
Example,
CA8B / 2B

         4B6
2B/CA92
     AC    
     1E9
     1D9
        102
        102



No comments:

Post a Comment