Thursday 12 December 2013

NUMBER SYSTEM CONVERSION


 السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ

NUMBER SYSTEM CONVERSION

hello,today i gonna teach you how to convert :
  • decimal - binary 
  •  binary - decimal 
  •  decimal - hexadecimal 
  •  hexadecimal - decimal


1 . How to convert decimal to binary

In order to convert decimal number x to binary number:
For decimal number x:
  1. Get the highest power of 2 that is less than the decimal number x:
    2n < x, (n=1,2,3,...)
  2. The high binary digit is equal 1:
    dn = 1
  3. Calculate the difference Δ of the number x and he power of 2, 2n:
    Δ = x - 2n
  4. Repeat step #1 with the difference until the result is 0.

for the example :
         Convert x=13 to binary.

Solution :

n=3, 23=8 < 13
n=4, 24=16 > 13
So
= 3
d3 = 1
Δ = 13 - 23 = 5
= 2, x = Δ = 5
d2 = 1
Δ = 5 - 22 = 1
= 1, x = Δ = 1
d2 = 0
= 0, x = Δ = 1
d0 = 1
Δ = 1 - 1 = 0
(d3d2d1d0)  = 1101
So 13 in decimal is equal to 1101 in binary:
x = 1310 = 11012


                                     this video shown to convert decimal to binary in easier way.


2 . How to convert binary to decimal 

The decimal number is equal to the sum of powers of 2 of the binary number's '1' digits place:
binary number:111001
power of 2:252423222120
1110012 = 1·25+1·24+1·23+0·22+0·21+1·20 = 57

                                                        this video is show how to convert binary to decimal

3 . How to convert from decimal to hexadecimal

For decimal number x:
  1. Get the highest power of 16 that is less than the decimal number x:
    16n < x, (n=1,2,3,...)
  2. The high hex digit is equal to the integer if the decimal number x divided by the highest power of 16 that is smaller than x:
    dn = int(x / 16n)
  3. Calculate the difference Δ of the number x and the hex digit dn times the power of 16, 16n:
    Δ = x - dn × 16n
  4. Repeat step #1 with the difference result until the result is 0.


for example :


Convert x=603 to hex:
n=2, 162=256 < 603
n=3, 163=4096 > 603
So
= 2
d2 = int(603 / 162) = 2
Δ = 603 - 2×162 = 91
= 1, x = Δ = 91
d1 = int(91 / 161) = 5
Δ = 91 - 5×161 = 11
= 0, x = Δ = 11
d0 = int(11 / 160) = 1110 = B16
Δ = 11 - 11×160 = 0
(d2d1d0)  = 25B
So
x = 60310 = 25B16

                                                   this video shown how to convert decimal to hexadecimal


4 . How to convert from hexadecimal to decimal 

         A regular decimal number is the sum of the digits multiplied with its power of 10.


Example #1 :

137 in base 10 is equal to each digit multiplied with its corresponding power of 10:
           13710 = 1×102+3×101+7×100 = 100+30+7
Hex numbers are read the same way, but each digit counts the power of 16 instead of power of 10.
Multiply each digit of the hex number with its corresponding power of 16.


Example #2 :

3B in base 16 is equal to each digit multiplied with its corresponding power of 16:
          3B16 = 3×161+11×160 = 48+11 = 59


Example #3 :

E7A9 in base 16 is equal to each digit multiplied with its corresponding power of 16:
          E7A916 = 14×163+7×162+10×161+9×16= 57344+1792+160+9 =59305


                                        this video shown how to convert hexadecimal to decimal



2's complement number
  • Positive Numbers
- Positive 2's complement numbers are represented as the simple binary.
  • Negative Numbers
- Negative 2's complement numbers are represented as the binary number that when added to a positive number of the same magnitude equals zero.

Integer2's Complement
SignedUnsigned
550000 0101
440000 0100
330000 0011
220000 0010
110000 0001
000000 0000
-12551111 1111
-22541111 1110
-32531111 1101
-42521111 1100
-52511111 1011
Note:  The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometimes called the sign bit.
If the sign bit is zero,
          then the number is greater than or equal to zero, or positive.
If the sign bit is one,
then the number is less than zero, or negative.

Calculation of 2's Complement

To calculate the 2's complement of an integer, invert the binary equivalent of the number by changing all of the ones to zeroes and all of the zeroes to ones (also called 1's complement), and then add one.
For example,
0001 0001(binary 17)   such that   1110 1111(two's complement -17)
 
NOT(0001 0001) = 1110 1110  (Invert bits)
1110 1110 + 0000 0001 = 1110 1111  (Add 1)

2's Complement Addition

Two's complement addition follows the same rules as binary addition.
For example,
5 + (-3)  =  2     0000 0101 = +5
+ 1111 1101
 = -3
  0000 0010 = +2

2's Complement Subtraction

Two's complement subtraction is the binary addition of the minuend to the 2's complement of the subtrahend (adding a negative number is the same as subtracting a positive one).
For example,
7 - 12  =  (-5)     0000 0111 = +7
+ 1111 0100
 = -12
  1111 1011 = -5

2's Complement Multiplication

Two's complement multiplication follows the same rules as binary multiplication.
For example,
(-4) × 4  =  (-16)     1111 1100 = -4
× 0000 0100
 = +4
  1111 0000 = -16

2's Complement Division

Two's complement division is repeated 2's complement subtraction. The 2's complement of the divisor is calculated, then added to the dividend. For the next subtraction cycle, the quotient replaces the dividend. This repeats until the quotient is too small for subtraction or is zero, then it becomes the remainder. The final answer is the total of subtraction cycles plus the remainder.
For example,
7 ÷ 3  =  2 remainder 1     0000 0111 = +7     0000 0100 = +4
+ 1111 1101
 = -3+ 1111 1101
 = -3
  0000 0100 = +4  0000 0001 = +1 (remainder)

Sign Extension

To extend a signed integer from 8 bits to 16 bits or from 16 bits to 32 bits, append additional bits on the left side of the number. Fill each extra bit with the value of the smaller number's most significant bit (the sign bit).
For example,
Signed Integer8-bit Representation16-bit Representation
-11111 11111111 1111 1111 1111
+10000 00010000 0000 0000 0001


posted by < MOHD SYUKRI BIN MAT LAZIM >

               < B031310013 >

No comments:

Post a Comment