If we let $B = b_{n−1}b_{n−2} · · · b_1b_0$ be an $n$-bit $2$’s complement integer. How can we show that the decimal value of $B$ is $−b_{n−1}\cdot2^{n−1} + b_{n−2} \cdot 2^{n−2} + b_{n−3}\cdot 2^{n−3} + \cdots + b_1\cdot 2 + b_0$.
Prove decimal number pattern for its n-bit 2's compliment
2
$\begingroup$
arithmetic
binary
number-systems
-
0What definition of *2's complement* do you use? – 2017-02-07
-
0Could you clarify what you mean by definition 2's complement? – 2017-02-07
-
0You say that $B$ is an `an n-bit 2’s complement integer`. What do you mean by that? You must be using *some* definition of $2$'s complement since you ask about it. This matters because there are contexts where the $2$'s complement is *defined* by the expression you quote, in which case there is nothing to prove. So, I assume that you are using a different definition, but then you need to spell out which one. – 2017-02-07
-
0The negative of a binary number represented by switching all ones to zeros and all zeros to ones and then adding one to the result. This should lead to 2 cases with the signed bit being negative or the signed bit being positive – 2017-02-07
1 Answers
1
Hint: let $\;A=-B\;$ then, by the definition of $2$'s complement, $A$ is obtained from $B$ by flipping all bits and adding $1\,$:
$$ A = (1-b_{n-1})\cdot 2^{n-1} + (1-b_{n-2})\cdot 2^{n-2} + \cdots + (1-b_1) \cdot 2 + (1-b_0) + 1 $$
Let $B\,'$ be the given expression $B\,' = −b_{n−1}\cdot2^{n−1} + b_{n−2} \cdot 2^{n−2} + \cdots + b_1\cdot 2 + b_0\,$. Then:
$$ \require{cancel} \begin{align} A + B\,' & = - 2 b_{n-1}\cdot 2^{n-1} + (2^{n-1}+2^{n-2}+\cdots+2+1) + 1 = \\ & = -b_{n-1} \cdot 2^{n} + (2^n - \cancel{1}) + \cancel{1} \\ & \equiv \;0 \pmod{2^n} \end{align} $$
Since $2$'s complement arithmetic is $\bmod 2^n\;$ it follows that $A+B\,'=0$ $\iff$ $B\,'=-A=B$.
-
0@HassanArshad Edited for better clarity. – 2017-02-07