# $2^x + 2^y = 129$: how to find the $x$ and $y$?

Sorry for my math language and the question header; I'm not capable of the terms used for the mathematics to ask the question via text; so I had to use the example above; feel free to edit if you can keep the meaning the same.

So the question is like this: I know that the total is uniquely identifies the used exponential constants while using the base as $2$; like $2^x + 2^y = 129$ then the $x=0$ and $y=7$.

So I couldn't think of a function to get the values like $\operatorname{func}(129) = [0,7]$.

Thanks in advance. Note: I know it's dumb to ask that but help is appreciated.

-
actually $x=0$ ($129=1+128$) – Andrea Mori Mar 27 '12 at 13:54
@AndreaMori sorry for that(: – Beytan Kurt Mar 27 '12 at 13:55

The function you are looking for is called dec2bin, when you are using Matlab. It would convert $129_{10}$ in decimal to $10000001_2$ in binary notation. As dec2base it works for other bases as well.

-
Thanks for that, I should have thought binary way while all the problem is base 2; thanks(: – Beytan Kurt Mar 27 '12 at 14:05
I would also like to mention Windows calculator has a programmer mode. Simply input the number as a decimal number and it will show you the binary representation with spaces every 4 bits to make counting easier. – Mike Mar 27 '12 at 17:31
Thanks but I'll use it for programming, so no calculator included. – Beytan Kurt Mar 27 '12 at 19:03

If $x>0 ~\text{and}~y>0$ then $2^x+2^y$ is an even number . Hence :

$(x,y)=\{(0,7),(7,0)\}$

-
I couldn't understand how you could find the result?? there's no tip to find 0 or 7?? – Beytan Kurt Mar 27 '12 at 14:01
$2^x+2^y$ can be odd number only if $x=0 ~\text{or}~ y=0$ , therefore it is easy to calculate that value of the second variable has to be $7$ . – pedja Mar 27 '12 at 14:08
I've asked for a function or a method to evaluate; your answer gives the how easy it is explanation; not the method but thanks. – Beytan Kurt Mar 27 '12 at 14:33

I'm not sure what is actually the question, but the problem of writing a number $n\in\Bbb N$ as a sum of powers of $2$ is equivalent to finding its expression in base $2$.

-
I don't think that 2^x + 2^y = 2^(x+y); the question is a workaround to keep a single number that could give multiple selection numbers like categoryA=0, categoryB=1, categoryZ=7 then when a result is given like 129 I can uniquely identify that catA and catZ is used with a single result – Beytan Kurt Mar 27 '12 at 14:01
As I told you, it is equivalent to find the expansion of n in base 2 and this is obtained by a repeated division by 2 keeping track of the remainders. For instance $129=2\cdot64+1$, $64=2\cdot32+0$, $32=2\cdot16+0$, $16=2\cdot8+0$, $8=2\cdot4+0$, $4=2\cdot2+0$, $2=2\cdot1+0$ and $1=2\cdot0+1$. Thus, $129=10000001$ (binary), i.e. $129=2^0+2^7$ because you have $1$ only in the $0$-th and $7$-th place. – Andrea Mori Mar 27 '12 at 16:02
Thanks a lot (: – Beytan Kurt Mar 27 '12 at 19:01

Hint $\$ For naturals $\rm\:b>1,\ x < y,\:$ if $\rm\: n\: =\: b^{x} + b^{y} =\: b^x\: (1 + b^{y-x})\:$ then $\rm\:x\:$ is determined uniquely as the greatest power of $\rm\:b\:$ that divides $\rm\:n,\:$ and $\rm\:y\:$ is determined uniquely as $\rm\:x\:$ plus the greatest power of $\rm\:b\:$ that divides $\rm\:n/b^{x}-1.$

This is a special case of the existence and uniqueness of radix representation, which follows from that for the division algorithm (here repeated division by the radix $\rm b$).

-