Powers of Two question
I'm working with some data that is bitwise OR'd, meaning I'll have a number, such as 16391, and I'll want to find the individual 'powers of 2' that make up the number. I have this calculation that correctly determines the first power of two, and I'd like to know if anyone can show me a better/cleaner way to do it.
2 ^ Floor ( Log ( number ) / Log ( 2 ) )
Further, since I'd like to know all the powers of two, I'd like to know if there is a better/cleaner way to do this custom function:
PowersOfTwo ( number ) =
Floor ( number ) = 1; 1
Floor ( number ) > 1; 2 ^ Floor ( Log ( number ) / Log ( 2 ) ) & ¶ & PowersOfTwo ( number - 2 ^ Floor ( Log ( number ) / Log ( 2 ) ) )