def powers_finder(num):
    d = []
while sum(d) < num:
    p = powers_of_2()
a = b = 1
while sum(d) + a <= num:
    b = a
a = next(p)
d.append(b)
d.reverse()
return d

def powers_of_2():
    n = 1
while 1:
    yield n
n *= 2
How do I decompose a number into powers of 2?