I am looking at https://en.wikipedia.org/wiki/Negative_base as a reference for converting base 10 to base -3 example. Converting back from -3 base to base 10 does not yield the same result. The example under calculation does not make sense: (146) in base 10 => 20121 in base -3 I think it should be 12102 in base -3 (digits reversed)
2*(-3)^0 + 0*(-3)^1 + 1*(-3)^2 + 2*(-3)^3 + 1*(-3)^4 = 2 - 0 + 9 -54 + 81 = 38 in base 10
Either answer won't convert back to 146 in base 10. What am I missing?
Able to track down the issue with the wiki. Thanks to Link to help me figure out.
146 / -3 = -48, remainder 2 [since 146 = -3*-48 + 2]
-48 / -3 = 16, remainder 0 [since -48 = -3*16 + 0]
16 / -3 = -5, remainder 1 [since 16 = -3*-5 + 1]
-5 / -3 = 2, remainder 1 [since -5 = -3*2 + 1]
The last two lines are wrong in the wiki work, and they failed to write the answer starting with the last remainder as they said. The answer is 21102 as posted by Scott.
2(-3)^4 + 1(-3)^3 + 1(-3)^2 + 0(-3)^1 + 2(-3)^0 = 162 - 27 + 9 + 0 + 2 = 146
In general, If the remainder is negative, add 1 to the quotient and add the absolute value of the base to the remainder.