Ok , I just worked out that every natural number can be expressed as sum of powers of 2, eg: (9 = 2^3 + 2 ^0). I am looking for an algorithm which does the splitting of natural number into powers of 2 efficiently.
closed as unclear what you're asking by Kuba, Yves Klett, Mr.Wizard♦ Feb 3 '14 at 12:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.
As mentioned in the comment above,
and then put a '1' wherever that list doesn't have a '0':
You can improve the speed a bit by not calculating the powers of 2, but by shifting the bit in the test pattern to the right position:
Or you can bitshift the number-under-test to the right and compare with '1' and reverse the result:
As usual, there is more than just one way to skin this particular cat...