I am trying to write a c# method which accepts an integer as an input and returns a list of integers which are powers of 2 whose sum is equal to input integer
For example
Input Integer :15
Output of this should be 1(2^0), 2 (2^1), 4 (2^2), 8 (2^3)
Sum of above integers is 15 = Input Integer
Input Integer :13
Output of this should be 1(2^0), 4 (2^2), 8 (2^3)
Sum of above integers is 13 = Input Integer
Input Integer :8
Output of this should be: 8 (2^3)
Sum of above integers is 15 = Input Integer
May I know a good way to do this?