1
$\begingroup$

I'm studying ones' complement representation and I read in a book that a negative number in ones' complement is a pseudo-positive of value $R^n - 1 - |x|$.

However there is no demostration and I can't find it anywhere. If someone could tell me the reason I will be very thankful.

$\endgroup$
1
$\begingroup$

One's complement stores negative numbers as their bitwise negation.

Suppose we're working in $b$ bits. A positive integer $x$ is represented in binary by writing it as $x = \sum_{i=0}^b a_i2^i$, where each $a_i\in\{0,1\}$. The bitwise negation of $x$, then, is $$\overline{x} = \sum_{i=0}^b (1-a_i)2^i = \sum_{i=0}^b 2^i - \sum_{i=0}^b a_i2^i = 2^b - 1 - x\,.$$

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Yes, this was what I wanted to know. Thanks! $\endgroup$ – Joseph Jul 10 '15 at 18:44
1
$\begingroup$

You are asking two questions:

  1. How can I prove that negative numbers are stored as pseudopositive?

  2. Why are negative numbers stored as pseudopositive?

The answer to the first question is that no proof is needed, since one's complement is a way of representing signed numbers as unsigned numbers, and it specifies that negative numbers are stored in this specific way. There is nothing to prove here, just read the definition of one's complement. In other words, this is true by definition.

Regarding the second question, storing numbers in this way facilitates arithmetic. For example, to add two numbers, you just add them as unsigned numbers, with an extra little fiddling depending on the sign bits; in two's complement you don't even need the extra fiddling.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Actually, Joseph is asking exactly one question, and it's neither of the ones you answer. The question is, how is it that the definition of ones' complement causes the negative number $-x$ to be represented as the specific positive $2^n-1-|x|$? $\endgroup$ – David Richerby Jul 10 '15 at 14:07
  • $\begingroup$ I fail to see how this differs from 1 above, but I guess your answer will make this more clear. $\endgroup$ – Yuval Filmus Jul 10 '15 at 14:08
  • $\begingroup$ It differs because it asks why $-x$ is represented by a specific positive number, not why it's represented by any old positive number. $\endgroup$ – David Richerby Jul 10 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.