Is there an algorithm to split a number into the sum of powers of 2? Am I able to split, lets say 76, into the sum of powers of two, through an algorithm and without cycling through possible combinations?
For the example above, the answer would be '2^6+2^3+2^2' or just simply the exponents, so '6,3,2'
Thanks in advance.
 A: Make successive divisions by $2$ and note the remainders, until the quotient is $0$:
$$\begin{array}{r|cc}
76&0\\38&0\\19&1\\9&1&\uparrow\\4&0\\2&0\\1&1
\end{array}$$
The binary digits of $76$ are $\;\color{red}{1001100}_2$. In other words
$$76=2^6+2^3+2^2.$$
This is because, if you write the Euclidean division equalities for each of these divisions, you have (Horner scheme)
\begin{align*}
76&=2\cdot 38 =2(2\cdot 19))=2(2(2\cdot 9+1))=2(2(2(2\cdot 4+1)+1))
\\&=2(2(2(2(2\cdot 2)+1)+1))=2(2(2(2(2(2\cdot 1))+1)+1))
\end{align*}
A: Hint: if you are seriously asking whether there is an algorithm for calculating the binary representation of a number, then the answer is yes. Google for "radix conversion" to learn more.
A: $log_2 76 ≈ 6.248$
$\lfloor log_2 76 \rfloor =$ 6
$76-2^{6}=12$
$log_2 12 ≈ 3.585$
$\lfloor log_2 12 \rfloor =$ 3
$12-2^3 = 4$
$log_2 4 =$ 2
A: C# function for split the given number into sum of power of 2
 public static List<long> GetSumOfPowerOfTwo(long n)
    {

        var reminders = new List<int>();
        var powerOfTwo = new List<long>();
        while (n > 0)
        {
            reminders.Add((int)n % 2);
            n = n / 2;
        }
        for (var i = 0; i < reminders.Count; i++)
        {
            if (reminders[i] == 1)
            {
                powerOfTwo.Add((long)System.Math.Pow(2, i));
            }
        }
        return powerOfTwo;
    }

A: The algorithm is as follows in python - you just iterate through the remainder - works for any base (radix) not just 2 :
def deconstruct(aNum, aBase):
    primeComps = []  #initialise array to hold the indexes
    num = aNum
    while num >= 1:
        index = int(math.floor(math.log(num,aBase)))
        #index = ilog(num,aBase)
        num = num - (aBase ** index) 
        primeComps.append(int(index)) # append each index into the array
    return primeComps

note instead of using the floor of the log to some radix
you can calculate the ilog, which is still based on the old idea of divide by 2 or divide by some radix - the ilog or index returned is the count of the quotients
def ilog(aNum, aBase):
    count = 0
    temp = aNum
    while temp >= (aBase):
        count = count + 1
        temp = temp/aBase
    return count

A very useful algorithm for information security - if anyone wants to know why I can explain 
