I'm pretty confused so I hope I don't mix up the different terms here.
The two's complement representation of decimal
0
is simply000
The two's complement of
000
is111
- I imagine that complementing a number is equivalent to flipping bits in binary
The nine's complement of
000
is999
- This is what confuses me. Are two's complement and nine's complement similar (except for the base change obviously)?
- If they are, then I'd expect the nine's complement of
000
to be888
because8
is the biggest digit in radix9
and therefore the complement operation would assign the highest digit (8
) to the lowest value input (0
) [I imagine a folding from the center]
Obviously this is totally wrong but I'm not sure which part I've misunderstood.
0
is0
. It's what you get by subtracting from 0, and-0 == 0
. (Or from flipping the bits and adding one: How to prove that the C statement -x, ~x+1, and ~(x-1) yield the same results?). Flipping all the bits is the one's complement inverse. See also en.wikipedia.org/wiki/Two%27s_complement $\endgroup$