This is an exercise from Royden Real Analysis:
Let $p$ be a natural number greater than 1, and $x$ a real number, $0 \leq x \leq 1$. Show that there is a sequence $\{a_n\}$ of integers with $0 \leq a_n < p$ for each $n$ such that $$ x = \sum_{n=1}^\infty \dfrac{a_n}{p^n}$$ and that this sequence is unique except when $x$ is of the form $q/p^n$, in which case there are exactly two such sequences. Show that, conversely, if $\{a_n\}$ is any sequence of integers with $0\leq a_n<p$ the series above converges to a real number $x$ with $0\leq x \leq 1$.
MY ATTEMPT:
Any number $x\in [0,1]$ can be written out in its decimal form as $x=0.d_1d_2d_3\ldots$ where $d_i$ are integers between $0$ and $9$. So we have $$x = \sum_{n=1}^\infty \dfrac{d_n}{10^n} = \sum_{n=1}^\infty \dfrac{\tfrac{p^n}{10^n}d_n}{p^n} = \sum_{n=1}^\infty \dfrac{a_n}{p^n}$$ However its not readily apparent to me that this construction guarentees $a_n<p$. Furthermore I am a bit stuck on showing this is unique unless $x=q/p^n$.
ATTEMPT 2: (Forward) Let $a_n = (xp^n\mod{p})$. Since for any $y\in\mathbb{R}$, $(y\mod p) \in \left\{0,\ldots,p-1\right\}$ we have $0\leq a_n < p$. Let $x_N$ be the partial sum $$x_N = \sum_{n=1}^N \dfrac{a_n}{p^n}$$ We want to show that $\lim_{n\to\infty}x-x_N=0$. (need to show that) $$x-x_N = r_N < \dfrac{1}{p^N}$$ and so $$\lim_{N\to\infty} x-x_N = \lim_{N\to\infty} \dfrac{1}{p^N}=0$$
(Backward)