1

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?

  • $3^3=27$ so the sum should be $2-0+9-54+81=38$. – scott Jan 11 '17 at 21:24
  • I get 146 (in decimal) is represented by 21102 in negaternary. Not sure how the wiki page works it out. – scott Jan 11 '17 at 21:33
  • Thanks for catching the addition mistake. Fixed it. Can you please explain how you got 21102? was following wiki instructions and dividing by -3 and taking remainder, creating sequence starting from unit digit. Not sure where I messed up. – Gunjan Jain - MSFT Jan 11 '17 at 22:18
  • I got 21102 by reverse-engineering it. I couldn't follow the instructions on the wiki, either. – scott Jan 11 '17 at 22:58
  • Thanks Scott. I am trying to teach my kid, so if someone has a systematic technique, let me know. – Gunjan Jain - MSFT Jan 12 '17 at 19:35

1 Answers1

0

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]

2 / -3 =   0, remainder 2  [since   2 = -3*0   + 2]

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.

Glorfindel
  • 3,955