I am trying to teach myself about p-adic numbers, and I came across an interesting property. Consider the following expansions:

$\displaystyle \displaystyle \begin{align*}-\frac{1}{3} & = \ldots 010101._2 \\ -\frac{2}{3} & = \ldots 101010._2 \\ -\frac{1}{9} & = \ldots 000111._2 \\ -\frac{2}{9} & = \ldots 001110._2 \\ -\frac{4}{9} & = \ldots 011100._2 \\ -\frac{8}{9} & = \ldots 111000._2 \\ -\frac{7}{9} & = \ldots 110001._2 \\ -\frac{5}{9} & = \ldots 100011._2 \end{align*}$

In the case of $\displaystyle -\frac{1}{3}$, the repeating pattern is two digits, and similarly for negative two-thirds. In the case of the six expansions where the denominator is nine, the six digits shown repeat to the left. I understand multiplying by powers of 2 is essentially bit shifting, so those all make sense, but $\displaystyle 16 \cong 7 (9)$ and $\displaystyle 32 \cong 5 (9)$. In other words, to get all rotations of the repeated digits, you simply multiply by all powers of 2 mod 9. This works when the denominator is 27 as well (there are 18 digits that repeat infinitely to the left, and 18 units of the local ring $\displaystyle \mathbb{Z} / 27 \mathbb{Z}$, and the operation of multiplication by 2 mod 27 does indeed rotate the 18 digits). Is there a way to prove this works when the denominator is any power of 3? I can prove that the number of repeated digits in the 2-adic expansion of $\displaystyle -\frac{1}{3^n}$ is $\displaystyle 2\cdot 3^{n-1}$. This is actually relatively simple since a simple induction argument shows that $\displaystyle 3^n$ always divides $\displaystyle 4^{3^{n-1}} - 1$ and

$\displaystyle -\frac{1}{3^n} = \frac{4^{3^{n-1}} - 1}{3^n}\frac{1}{1 - 4^{3^{n-1}}} = \frac{4^{3^{n-1}} - 1}{3^n}\sum_{i \ge 0} \left( 4^{3^{n-1}} \right)^i $

Then, since $\displaystyle 0 < \frac{4^{3^{n-1}}-1}{3^n} < 4^{3^{n-1}}$, which is a positive integer, its base-2 expansion takes at most $\displaystyle 2\cdot 3^{n-1}$ digits, so the expansion repeats that many digits. Also, since multiplying by any power of 2 mod $\displaystyle 3^n$ will give a unit of $\displaystyle \mathbb{Z} / 3^n \mathbb{Z}$, multiplying the whole fraction by that unit will still take no more than $\displaystyle 2\cdot 3^{n-1}$ digits to express in base-2, so that is still the number of repeating digits. I just don't have any idea how to show that you always get a rotation of the digits.

Edit: I am guessing the Division Algorithm might be useful. Consider the following:

$\displaystyle 32 = 9q + r$ has the solution $\displaystyle 32 = 9\cdot 3 + 5$. Now, $\displaystyle -\frac{32}{9} = \ldots 00011100000._2 $ where the six digits to the left of the five zeros adjacent to the decimal point are the repeated digits. Essentially, I just bit-shifted five places to the left. Now, $\displaystyle 3-\frac{32}{9} = \ldots 00011100011._2 = -\frac{5}{9}$ which is also $\displaystyle \left\lfloor \frac{32}{9}\right\rfloor - \frac{32}{9}$. I am not quite sure how to relate this to the rotation, though.