2's complement:

2's complement:


The 2's complement of a given binary number X (=! 0) with integer part of n digits can be obtained as follows,
(a) By calculating the result of 2n - X.
For example: Suppose you want to obtain 2's complement of (  10101)2,
  Now X = 10101 and n = 5 so on substituting these values ​​in the above formula, we get 2's complement of (10101)2
= 25 - (10101)2
= (100000 - 10101)2
= (01011)2 
(b) By leaving all least significant zeros and the first non-zero digit unchanged, and then replacing 1's by 0's and 0's by 1's in all other higher significant digits. 
For example: Suppose you want to obtain 2's complement of (110101101000)2
Now on moving from right to left we have three 0's and then first non-zero digit 1. So we leave them unchanged.  All other digits are simply complemented
110 1011010 0,
0's changed to 1's
1's changed to 0's
= 001010011000   -> 2's complement
(c) By adding 2-m to the least significant digit of the 1's complement of the given number.  Here, m is the number of digits in the fractional part. 
For example: Suppose you want to obtain 2's complement of (011010) .
Now we first calculate 1's complement of (011010)2 which is equal to (100101)2. On adding 1 (i.e. 20) to the least significant digit, we get
1 0 0 1 0 1 + 1
= 1 0 0 1 1 0  ->   2's Complement
Therefore, 2's Complement of (011010)2, is (100110)2,
NOTE: Complement of the Complement  restores the number to its original value. 
 SUBTRACTION USING 2's COMPLEMENT METHOD:
The subtraction of two positive binary numbers (M - N) using the method discussed earlier easier but less effective.  In digital components, the subtraction is performed using complement and addition as follows:
1. Add the minuend M to the 2's complement of the subtrahend N.
i.e.  M - N = M + (2's complement of N) 
 2. Examine the result obtained in step 1, 
 (a) If an end carry is produced then simply discard it. 
(b) If no end carry is produced, take the 2's complement of the result obtained in step 1 and place a negative sign in front. 
EXAMPLE:
2. Subtract (011011), from (110111), using 2's complement method. 
SOLUTION: Here M = (110111), and N = (011011),
2's complement of N i.e.  (011011)2 = (100101)2
Now on adding it to the minuend M. we get
1 1 0 1 1 1 + 1 0 0 1 0 1      <-  2’s complement
= 1 0 1 1 1 0 0   <-  2’s complement
 as end carry is produced so as per rule 2(a) we discard it.
So, (110111)2 - (011011)2 = (011100)2 
 2. Subtract (11100), from (10011), using 2's complement method.
SOLUTION: Here M = (10011)2 and N = (11100)2 2's complement of (11100)2 = (00100)2
Now, add it  to the minuend M, we get
1 0 0 1 1 + 0 0 1 0 0    <- 2’s complement
= 1 0 1 1 1      
 as no end carry is produced, so as per rule 2 (b). we take 2's complement of the result obtained i.e. (10111)2 .
2's complement of (10111)2 = (01001)2
Now place  a negative sign in front i.e. - (01001)2
Therefore, (10011)2 - (11100)2 = - (01001)2

No comments

Powered by Blogger.