Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I finally understood how to convert from base 10 to 10's complemnt here

But how do I convert back? How do I know what sign it is? In 2s complement, its the LSB, 1 means negetive else positive. For 10s complement?

If

$$-1122_{10} = 9999 - 1122 + 1 = 8878_{10s}$$

$$8878_{10s} = 9999 - 8878 - 1 = -1122_{10}$$

But why in another problem,

$$899_{10} – 7212_{10} = 00899_{10s} + 92788_{10s} = 93687_{10s}$$

$$93687_{10s} = 99999 - 93687 - 1 = -6311_{10}$$

Correct answer should be $-6313_{10}$. Probably my method of converting from 10s complement to decimal is wrong?

Hmm... I suspect its I should be doing $100000 - 93687$ ... but why did it work in the 1st case? How do I determine the sign? LS"B" 9 means negative?

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

In your equations, you write

$$8878_{10s} = 9999 - 8878 - 1 = -1122_{10}$$

This is incorrect without the use of proper brackets, since

$$8878_{10s} = 9999 - 8878 - 1 = 9999 - 8879 = -1120_{10}$$

Instead, I think you meant to write

$$8878_{10s} = 9999 - (8878 - 1) = 9999 - 8877 = -1122_{10}$$

This then also shows why your final solution is wrong. Add brackets, and you get

$$93687_{10s} = 99999 - (93687 - 1) = 99999 - 93686 = -6313_{10}$$

And, like you write, it would be much easier to write $10000 - x$ rather than $9999 - (x - 1)$, which is actually the same.

share|improve this answer
add comment

But how do I convert back?

In exactly the same way. Complements are involutions.

How do I know what sign it is?

Look at the leading digit. 0..4 => positive; 5..9 => negative.

share|improve this answer
add comment

Thijs Laarhoven has already pointed out the sign errors in your calculations. As for the original question ("How do I know what sign it is?"), you just have to decide on some sign convention: if the result, reduced modulo $10^n$, is less than some threshold $M$, then you should interpret it as positive, otherwise as negative.

One natural choice of threshold is $M = 10^n/2$, which is equivalent to the rule suggested by Peter Taylor: if the $n$-th digit is $5$ or greater, the number is negative. However, pretty much any other choice of $0 < M \le 10^n$ could be used as well. ($M=10^n$ corresponds to unsigned arithmetic modulo $10^n$.) In any case, you will always experience arithmetic overflow whenever the result becomes greater than or equal to $M$ or less than $M-10^n$.

This is exactly the same situation as in base 2; the convention that numbers with the highest bit set are considered negative (i.e. $M = 2^n/2 = 2^{n-1}$) is just one possibility out of many. One advantage of this particular convention, and of the similar convention for base 10 suggested above, is that they ensure that negation consistently flips the sign of almost all non-zero numbers; the sole exception in both cases is $M \equiv -M$, which is congruent to its own negative.

This is an unavoidable consequence of $b$'s complement representation for even $b$: since there are an even number of possible numbers, and since one of them must represent zero, that leaves an odd number of numbers to be divided among the positives and negatives.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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