Originally posted by -X-
Hi, i've just got something really confusing me. If for example i want to represent -1 in 10's complement form. This will then equal to 999 right? But then, what if the computer wants to represent the actual number, '999'. How will it know whether it is representing a negative number, '-1' or the actual "999"? The Alan Fowler textbookd doesnt explain this.
Thanks, hope you understood me.
The computer has to understand the rules of the game (or the rules of the number system). If a computer was to use a 10's complement system like you discuss, then it would also need to know that 0-499 were positives (or more accurately non-negatives), and that 500-999 were negatives.
It's the same for two's complement in binary, the computer knows the first bit represents a negative power of two. In binary you only need to look at the highest order bit, as it conveniently splits the range into two equal ranges, the negatives when the bit is set (ie 1) and the non-negatives when it is not (ie 0).
The equivalent of this for your three digit base 10 system would be any number starting with 5, 6, 7, 8 or 9 is negative and any number starting with 0, 1, 2, 3 or 4 is non-negative. Your system will work; try doing some arithmetic...
(1) -1 + 1 using your system is performed as 999 + 1 = 1000, ignore the leading 1 and your answer is 0
(2) 10 - 20 using your system is performed as 10 + 980 = 990, 990 converts to -10.
(3) -6 * -3 using your system is performed as 994 * 997 = 991018, retain just the three digits used by your system, so the answer is 18
(4) 100 * 6 = 600, which in your system is -400, so just like binary twos complement, problems occur when answers are outside the range represented.
HTH
Sam