Why This alternative way for retrieving the Original number from 2'S complement number works?

600 Views Asked by At

I was reading a book to learn about conversion from 2'S complement number to origianl binary number.

During my past college study, I learened the following method for retrieving the Original number from 2'S complement:

Step-1: Take the 2'S complement number. 
Step-2: Subtract 1 from that 2'S complement number. 
Step-3: Complement the Output of Step-2. 

Ex: 

Step-1: 10101110

Step-2: 10101110 
       -00000001
       -----------
        10101101

Step-3: Complement(10101101) = 01010010 [Original Number]

However, the following method is another alternative way for retrieving the Original number from 2'S complement:

Step-1: Take the 2'S complement number. 
Step-2: Take a bigger number that has bit length = ( (bit length of that 2'S complement number) + 1 ) 
Step-3: Subtract Step-1 from Step-2  will return origianl number.

Ex: 

Step-1: 10101110

Step-2: bigger number = 100000000

Step-3: (From Step-2) 100000000
        (From Step-1) -10101110
        -----------------------
                     = 01010010 [Original Number]

can you please explain me the reason behind this in easy way.Thanks

1

There are 1 best solutions below

3
On BEST ANSWER

If you have an $n$-bit word $w$, flipping all of the bits is the same as subtracting it from $\underbrace{11\cdots 11}_n{}_2$ -- imagine subtracting binary digit for digit; there's never any borrows! Therefore your first procedure computes $$ \underbrace{11\cdots 11}_n{}_2 - (w-1) $$ By a simple algebraic rearrangement, this is the same as $$ \underbrace{11\cdots 11}_n{}_2 + 1 - w = 1\underbrace{00\cdots 00}_n{}_2 - w $$


Note that if you carry out the final subtraction bit for bit with the pencil-and-paper algorithm, you don't need to represent the initial $1$ in $1\underbrace{00\cdots00}_n{}_2$ explcitly -- just ignore the borrow out of bit $n-1$, working with a fixed $n$-bit word length. In that case the rule is simply $$ -w = \underbrace{00\cdots00}_n{}_2-w $$ that is, you negate a number by subtracting it from zero! This procedure works for negating any positive or negative 2's complement number, except for $-2^{n-1}$ whose negative cannot be represented.