1

For a number, say $x$, represented in base 2 with $w$ bits, such that, $$ x = a_{w-1} a_{w-2} \dots a_1 a_0 \text{ where $a_i$ $\epsilon $ $\{0,1\}$ $ \forall$ $ i$ $\epsilon$ $[0,w-1]$} $$ we can interpret it as a two's complement in two ways:

  1. $N = -a_{w-1} \cdot 2^{w-1} + \sum_{i=0}^{w-2} a_i \cdot 2^i $
  2. The negative of a number $y$ can be stored as $x$ if we define $x:= 2^w - y$

I am unable to fully comprehend how one leads to the other. The following is my work:

  • The first way describes an offset to the left of zero followed by increments towards zero. I can independently understand this technique. The $w-1$ bits to the right tells us how much we should move towards $0$ in the case where $a_{w-1}=1$
  • In the second perspective, the positive number $y$ is stored in $w-1$ bits. $y$'s value cannot exceed $(2^{w-1} -1 )$. So when we subtract it from $2^w$, i.e. from $1<<w$ (1 followed by w zeroes), the $w$th bit will always be $1$ since only by removing a value of $2^{w-1}$ or greater can we zero out that bit.
Now how do I connect the second point with the first mentally?

PS: This could be relevant but it hasn't helped me yet. Why Two's Complement works

0 Answers0