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.