Saturday 20 October 2012

Chapter 2 Number System Conversion

Arithmetic for Computers (Number Systems and Operations)

Number System Conversion

There are many type of number system, and here our conversion are focus on only 3 type of number systems which are binary(base 2) number, decimal(base 10) number and hexadecimal(base 16) number.


Positional Number System

Decimal number system is know as a positional number system, because the position for each digits inside the number are important. The position for every digits cannot be change arbitrary even the digits between 2 numbers are same but with the different digit position.


Example:

          357 = 3*(10^2)+5*(10^1)+7*(10^0)
                = 3*100 + 5*10 + 7*1
                = 300+50+7

If we make the digit position become 735, the value for the digit number will has a very different value with 357 value although the digits for the 2 numbers are same. In positional number system, the most left position will be the most large value, however the most right position is the smallest value.

                  ... 1000 ,  100  ,  10  ,   1

                  ... 10^3  , 10^2 ,10^1 , 10^0
The value for each positions are correspond to powers of the base of the number system. So for our decimal number system, which uses base 10, the place value are correspond to power of 10.
Before we start the conversion, let's have a look on number system conversion table.

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


Binary and Decimal number system conversion

Converting a binary number to decimal number:

Example: 100110
     1       0       0       1       1       0   the binary number
   2^5    2^4    2^3    2^2    2^1    2^0 place values
= 2^5 + 2^2 + 2^1
= 32  +   4  +  2
= 38

OR

1  ==>>  2^5          32
0  ==>>  2^4
0  ==>>  2^3
1  ==>>  2^2            4
1  ==>>  2^1       +   2
0  ==>>  2^0
=================
                             38

The binary system uses base 2, so the place value of the digit of the binary number correspond to power of 2.
The decimal value for the binary number of 100110 is 38(base 10).

For another example: 0.01011
                0.       0         1         0         1         1
              2^0     2^-1     2^-2     2^-3     2^-4     2^-5
           = 2^-2 + 2^-4 + 2^-5
           = 0.25 + 0.0625 + 0.03125
           = 0.34375

Converting a decimal number to binary number:

Example: 375
The calculation for convert decimal number to binary number as below are using an division calculation.
2|375
2|187  1    \
2| 93   1    \\
2| 46   1    \\\
2| 23   0    ----->>        combine all the remainder start from bottom to top:
2| 11   1    ----->>>>    101110111 << is the binary number for 375(decimal number)
2|   5   1    ----->>
2|   2   1    ///
2|   1   0    //
2|   0   1    /
The remainder for the division will be combined and formed into binary number 101110111 which is the binary number converted from 375(decimal number).

For another example: 0.3158
0.40625 * 2 = 0.8125 + 0 \
0.8125   * 2 = 0.625  + 1 \\    Combine all the remainder start from top to bottom:
0.625    * 2 = 0.25     + 0 >> 0.01001 << is the binary number for 0.3158(decimal number).
0.25      * 2 = 0.5      + 0 //
0.5       * 2 = 0          + 1 /
Binary and Hexadecimal number system conversion

Each digit position of the hexadecimal number system is represents a power of 16.
The reason of the common use for hexadecimal number is the relationship between the number 2 and 16. Sixteen is a power of 2(16=2^4). Because of this relationship, each digit of the hexadecimal are converted by each group(4 binary digits) of binary number. This make the conversion between hexadecimal and binary are very easy.

Converting a binary number to hexadecimal number:
Example: 11 1000 0001 1101 1111

0011 1000 0001 1101 1111    The first 2 digits for the binary number(11) do not form a group
   3      8      1      D      F       to convert to hexadecimal number, so we add 2 digits(00) in front of it to
                                           done the conversion.

Therefore, the hexadecimal number converted from 1000 0001 1101 1111(binary number) is 81DF.
For another example: 0.1101 1001 101


0. 1101 1001 1010    The last 3 binary digits do not form a group to convert to hexadecimal,
0.    D       9       A    so we add a digit(0) at behind of it to done the conversion.
Therefore, the hexadecimal number converted from 0.1101 1001 101(binary number) is 0.D9A.

Converting a hexadecimal number to binary number:

Example: ABD
   A     B      D
1010 1011 1101

Therefore, the binary number converted from ABD(hexadecimal number) is 1010 1011 1101.

For another example: 0.3A2
0.    3      A      2
0. 0011 1010 0010
Therefore, the binary number converted from 0.3A2(hexadecimal number) is 0. 0011 1010 001.

Decimal and Hexadecimal number system conversion

Converting decimal number to hexadecimal number:
Example: 110
16|110   6      Combine the number from top to bottom to form a hexadecimal number.
16|  14   E       The hexadecimal number is 6E.

Converting hexadecimal number to decimal number:
Example: AE9
A=10    16^2   ===>>>   10*(16^2)  =  2560
E=14    16^1   ===>>>   14*(16^1)  =    224
9=  9    16^0   ===>>>     9*(16^0)  =+     9
                                                   ======
                                                        2793


Therefore, the decimal number converted from AE9(hexadecimal number) is 2793.

NOTE: The decimal value of hexadecimal can be view from the system number conversion
           table.



No comments:

Post a Comment