Generalized representation for a sum of powers of 2 to represent a number

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Lets say there is positive number $n = 118$, which we want to represent as sum of powers of i.e. $2^k$ (while $n$ being always $>= 0$).



Following the repetitive division by powers of 2, we obtain that $n$ can be written as the sum of following powers of $2$:



$118$ = $2^6$ + $2^5$ + $2^4$ + $2^2$ + $2^1$



On the other hand, the solution $(sum_i=0^6 2^i = 127)$ is greater than $118$. My question is: how can we generalize this descending pattern of powers, through which we will know that we have to exclude $2^3$ and $2^0$ from the sum? Thanks.










share|cite|improve this question























  • Isn't $i = 0$?.
    – Enigsis
    Sep 3 at 8:05










  • The sum should start from $i = 0$ so what we should do is to exclude $2^0$ and $2^3$. Otherwise, if the sum starts from $i = 1$, the result should be $126$.
    – ArsenBerk
    Sep 3 at 8:05











  • True. Let me correct.
    – khan
    Sep 3 at 8:06














up vote
0
down vote

favorite












Lets say there is positive number $n = 118$, which we want to represent as sum of powers of i.e. $2^k$ (while $n$ being always $>= 0$).



Following the repetitive division by powers of 2, we obtain that $n$ can be written as the sum of following powers of $2$:



$118$ = $2^6$ + $2^5$ + $2^4$ + $2^2$ + $2^1$



On the other hand, the solution $(sum_i=0^6 2^i = 127)$ is greater than $118$. My question is: how can we generalize this descending pattern of powers, through which we will know that we have to exclude $2^3$ and $2^0$ from the sum? Thanks.










share|cite|improve this question























  • Isn't $i = 0$?.
    – Enigsis
    Sep 3 at 8:05










  • The sum should start from $i = 0$ so what we should do is to exclude $2^0$ and $2^3$. Otherwise, if the sum starts from $i = 1$, the result should be $126$.
    – ArsenBerk
    Sep 3 at 8:05











  • True. Let me correct.
    – khan
    Sep 3 at 8:06












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Lets say there is positive number $n = 118$, which we want to represent as sum of powers of i.e. $2^k$ (while $n$ being always $>= 0$).



Following the repetitive division by powers of 2, we obtain that $n$ can be written as the sum of following powers of $2$:



$118$ = $2^6$ + $2^5$ + $2^4$ + $2^2$ + $2^1$



On the other hand, the solution $(sum_i=0^6 2^i = 127)$ is greater than $118$. My question is: how can we generalize this descending pattern of powers, through which we will know that we have to exclude $2^3$ and $2^0$ from the sum? Thanks.










share|cite|improve this question















Lets say there is positive number $n = 118$, which we want to represent as sum of powers of i.e. $2^k$ (while $n$ being always $>= 0$).



Following the repetitive division by powers of 2, we obtain that $n$ can be written as the sum of following powers of $2$:



$118$ = $2^6$ + $2^5$ + $2^4$ + $2^2$ + $2^1$



On the other hand, the solution $(sum_i=0^6 2^i = 127)$ is greater than $118$. My question is: how can we generalize this descending pattern of powers, through which we will know that we have to exclude $2^3$ and $2^0$ from the sum? Thanks.







number-theory elementary-number-theory power-series






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Sep 3 at 8:14

























asked Sep 3 at 7:57









khan

1337




1337











  • Isn't $i = 0$?.
    – Enigsis
    Sep 3 at 8:05










  • The sum should start from $i = 0$ so what we should do is to exclude $2^0$ and $2^3$. Otherwise, if the sum starts from $i = 1$, the result should be $126$.
    – ArsenBerk
    Sep 3 at 8:05











  • True. Let me correct.
    – khan
    Sep 3 at 8:06
















  • Isn't $i = 0$?.
    – Enigsis
    Sep 3 at 8:05










  • The sum should start from $i = 0$ so what we should do is to exclude $2^0$ and $2^3$. Otherwise, if the sum starts from $i = 1$, the result should be $126$.
    – ArsenBerk
    Sep 3 at 8:05











  • True. Let me correct.
    – khan
    Sep 3 at 8:06















Isn't $i = 0$?.
– Enigsis
Sep 3 at 8:05




Isn't $i = 0$?.
– Enigsis
Sep 3 at 8:05












The sum should start from $i = 0$ so what we should do is to exclude $2^0$ and $2^3$. Otherwise, if the sum starts from $i = 1$, the result should be $126$.
– ArsenBerk
Sep 3 at 8:05





The sum should start from $i = 0$ so what we should do is to exclude $2^0$ and $2^3$. Otherwise, if the sum starts from $i = 1$, the result should be $126$.
– ArsenBerk
Sep 3 at 8:05













True. Let me correct.
– khan
Sep 3 at 8:06




True. Let me correct.
– khan
Sep 3 at 8:06










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Well, I can think of $2$ ways to do that:



1) We can represent the number in base $2$. When we do that, whenever we have a $0$ in base $2$ representation, corresponding power should be excluded.



For example, $118 = (1110110)_2$ so we should exclude $2^0$ and $2^3$.



2) This one is more like an algorithm. Let our number be $n$. Then, first we find smallest number $k$ such that $2^k - 1 ge n$. Then we find the difference $d = (2^k - 1) - n$ and express it by using powers of $2$. While doing this, we should find largest $m$ such that $2^m <= d$. Then do the same for $d - 2^m$ and continue this until $d = 0$. The $m$ values you find during this process will be the excluded powers.



For example, we have $n = 118$. Smallest number $k$ such that $2^k - 1 > n$ is $k = 7$ so we have $d = 9$. Then the largest $m$ such that $2^m le d$ is $m = 3$. So our new $d$ is $9-2^3 = 1$. Then the largest $m$ such that $2^m le d$ is $m = 0$ and our new difference is $0$ so we are done by excluding $2^3$ and $2^0$.






share|cite|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "69"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2903630%2fgeneralized-representation-for-a-sum-of-powers-of-2-to-represent-a-number%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Well, I can think of $2$ ways to do that:



    1) We can represent the number in base $2$. When we do that, whenever we have a $0$ in base $2$ representation, corresponding power should be excluded.



    For example, $118 = (1110110)_2$ so we should exclude $2^0$ and $2^3$.



    2) This one is more like an algorithm. Let our number be $n$. Then, first we find smallest number $k$ such that $2^k - 1 ge n$. Then we find the difference $d = (2^k - 1) - n$ and express it by using powers of $2$. While doing this, we should find largest $m$ such that $2^m <= d$. Then do the same for $d - 2^m$ and continue this until $d = 0$. The $m$ values you find during this process will be the excluded powers.



    For example, we have $n = 118$. Smallest number $k$ such that $2^k - 1 > n$ is $k = 7$ so we have $d = 9$. Then the largest $m$ such that $2^m le d$ is $m = 3$. So our new $d$ is $9-2^3 = 1$. Then the largest $m$ such that $2^m le d$ is $m = 0$ and our new difference is $0$ so we are done by excluding $2^3$ and $2^0$.






    share|cite|improve this answer
























      up vote
      0
      down vote













      Well, I can think of $2$ ways to do that:



      1) We can represent the number in base $2$. When we do that, whenever we have a $0$ in base $2$ representation, corresponding power should be excluded.



      For example, $118 = (1110110)_2$ so we should exclude $2^0$ and $2^3$.



      2) This one is more like an algorithm. Let our number be $n$. Then, first we find smallest number $k$ such that $2^k - 1 ge n$. Then we find the difference $d = (2^k - 1) - n$ and express it by using powers of $2$. While doing this, we should find largest $m$ such that $2^m <= d$. Then do the same for $d - 2^m$ and continue this until $d = 0$. The $m$ values you find during this process will be the excluded powers.



      For example, we have $n = 118$. Smallest number $k$ such that $2^k - 1 > n$ is $k = 7$ so we have $d = 9$. Then the largest $m$ such that $2^m le d$ is $m = 3$. So our new $d$ is $9-2^3 = 1$. Then the largest $m$ such that $2^m le d$ is $m = 0$ and our new difference is $0$ so we are done by excluding $2^3$ and $2^0$.






      share|cite|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Well, I can think of $2$ ways to do that:



        1) We can represent the number in base $2$. When we do that, whenever we have a $0$ in base $2$ representation, corresponding power should be excluded.



        For example, $118 = (1110110)_2$ so we should exclude $2^0$ and $2^3$.



        2) This one is more like an algorithm. Let our number be $n$. Then, first we find smallest number $k$ such that $2^k - 1 ge n$. Then we find the difference $d = (2^k - 1) - n$ and express it by using powers of $2$. While doing this, we should find largest $m$ such that $2^m <= d$. Then do the same for $d - 2^m$ and continue this until $d = 0$. The $m$ values you find during this process will be the excluded powers.



        For example, we have $n = 118$. Smallest number $k$ such that $2^k - 1 > n$ is $k = 7$ so we have $d = 9$. Then the largest $m$ such that $2^m le d$ is $m = 3$. So our new $d$ is $9-2^3 = 1$. Then the largest $m$ such that $2^m le d$ is $m = 0$ and our new difference is $0$ so we are done by excluding $2^3$ and $2^0$.






        share|cite|improve this answer












        Well, I can think of $2$ ways to do that:



        1) We can represent the number in base $2$. When we do that, whenever we have a $0$ in base $2$ representation, corresponding power should be excluded.



        For example, $118 = (1110110)_2$ so we should exclude $2^0$ and $2^3$.



        2) This one is more like an algorithm. Let our number be $n$. Then, first we find smallest number $k$ such that $2^k - 1 ge n$. Then we find the difference $d = (2^k - 1) - n$ and express it by using powers of $2$. While doing this, we should find largest $m$ such that $2^m <= d$. Then do the same for $d - 2^m$ and continue this until $d = 0$. The $m$ values you find during this process will be the excluded powers.



        For example, we have $n = 118$. Smallest number $k$ such that $2^k - 1 > n$ is $k = 7$ so we have $d = 9$. Then the largest $m$ such that $2^m le d$ is $m = 3$. So our new $d$ is $9-2^3 = 1$. Then the largest $m$ such that $2^m le d$ is $m = 0$ and our new difference is $0$ so we are done by excluding $2^3$ and $2^0$.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Sep 3 at 8:23









        ArsenBerk

        6,9521933




        6,9521933



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2903630%2fgeneralized-representation-for-a-sum-of-powers-of-2-to-represent-a-number%23new-answer', 'question_page');

            );

            Post as a guest













































































            這個網誌中的熱門文章

            tkz-euclide: tkzDrawCircle[R] not working

            How to combine Bézier curves to a surface?

            1st Magritte Awards