What is a simple algorithm you can feasibly do by hand to negate an integer in a negative base, such as negadecimal?
In positive bases, you can simply append a negative sign if it is not there, and remove it if it is:
Negate 123456
-> -123456
Negate -123456
-> 123456
In a negative base, however, it is not so easy, since both negative and positive numbers can be represented without any sort of explicit sign.
This should be the result in negadecimal:
Negate 123456
-> 98764
Negate 98764
-> 123456
I can't figure out a straightforward method (i.e. one that can be done with pencil and paper fairly mindlessly) to negate a negadecimal number. How could I do this?
Best Answer
Working from the right, the two extreme digits must add up to 0 or 10 (and can only add to 0 if they are both 0). If they add to 10 then carry one from the next sum. The next two digits to the left must add up to 0 or 10 if not carrying one, or if carrying one then add up to 1 or 11; if they add up to 10 or 11 then carry one from the next sum. And so on.
So starting with say 120034:
But we can ignore left-hand leading 0s so the negative of 120034 is 80186.