TITLE: Converting decimal(base 10) numbers to binary by repeatedly dividing by 2
QUESTION [20 upvotes]: A friend of mine had a homework assignment where he needed to convert decimal(base 10) numbers to binary. I helped him out and explained one of the ways I was taught to do this. 
The way I showed him was to repeatedly divide the number by 2 and then take the remainder, the binary number will be the remainders read from bottom to top. 
ex:  Convert 22 to a binary representation

22 / 2 = 11 R 0
11 / 2 = 5  R 1 
5  / 2 = 2  R 1
2  / 2 = 1  R 0
1  / 2 = 0  R 1

answer = 10110

After I showed him the algorithm and an example, he set off to do the rest of his problems. Today he sent me an email and asked me why this method works. I was sort of shocked by that question, I have never given a second thought to why this works, I only did as I was told knowing that if I performed this algorithm I would always get the right answer in binary. 
I thought about it for awhile and still can't seem to figure out WHY this method works, any help would be appreciated. This isn't for an assignment, merely my curiosity and frustration at not asking this question before. 
Thanks
Edit
Do you mind explaining how you went from:
$$n=e_0\times 2^0 + e_1\times 2^1 + \cdots + e^k\times 2^k$$ 
to
$$n=e_0 + 2\Bigl(e_1 + e_2\times 2 + \cdots + e_k\times 2^{k-1}\Bigr),$$
I am not following the transition to the closed form.

REPLY [18 votes]: It becomes crystal clear if you rewrite it as follows
$\rm\qquad\qquad 22\ =\ {\color{red} 0}\ +\ 2\ (11)$
$\rm\qquad\qquad\quad\ \ = \ {\color{red} 0}\ +\ 2\ ({\color{green} 1}\ +\ 2\ (5))$
$\rm\qquad\qquad\quad\ \ = \ {\color{red} 0}\ +\ 2\ ({\color{green} 1}\ +\ 2\ ({\color{magenta} 1}\ +\ 2\ (2)))$
$\rm\qquad\qquad\quad\ \ = \ {\color{red} 0}\ +\ 2\ ({\color{green} 1}\ +\ 2\ ({\color{magenta} 1}\ +\ 2\ ({\color{brown} 0}\ +\ 2\ (1))))$
$\rm\qquad\qquad\quad\ \ = \ {\color{red} 0}\cdot 2^0 + {\color{green} 1}\cdot 2^1 + {\color{magenta} 1}\cdot 2^2 + {\color{brown} 0}\cdot 2^3 + 1\cdot 2^4\  $ expanded to normal form: polynomial in $2$
$\rm\qquad\qquad\quad\ \ = \ 1{\color{brown} 0}{\color{magenta} 1}{\color{green} 1}{\color{red} 0}\ $ in binary notation (reverse the above color-codified binary digits)
Therefore the binary digits arise simply by iterating the process of division by 2, with remainder. See also my posts on Horner's method.