Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
You then take one away to get 781, the 9's-complement. But why didn't you just calculate the 9's-complement directly, like the example shows? It's as if you read a simple example and can't simply follow it as given. You add complexity that simply isn't there in the original.
Well, I did understand it, but I just wanted to find a way how. Beside just finding the 10's complement and subtracting 1 isn't really that complex, just a little more work.

Actually, I used the ~ and added ten to each digit since a ~digit tends to equal a negative number.
 
Last edited:
Well, I did understand it, but I just wanted to find a way how. Beside just finding the 10's complement and subtracting 1 isn't really that complex, just a little more work.

Actually, I used the ~ and added ten to each digit since a ~digit tends to equal a negative number.

"The complement of a decimal digit in the nines' complement system is the number that must be added to it to produce 9." (from the wikipedia article)

Expressed algebraically, where D is any decimal digit, and C is its 9's-complement:
Code:
D + C = 9
Now, using basic algebra to solve for C:
Code:
C = 9 - D

Ultimately, the test is whether the code works or not. So did you code it, and does it work? Does it handle negative numbers or not?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.