AnsweredAssumed Answered

Powers of Two question

Question asked by etripoli on Oct 7, 2009
Latest reply on Oct 9, 2009 by etripoli

Title

Powers of Two question

Post

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 ) =

Case (

Floor ( number ) = 1; 1

;

Floor ( number ) > 1; 2 ^ Floor ( Log ( number ) / Log ( 2 ) ) & ¶ & PowersOfTwo ( number - 2 ^ Floor ( Log ( number ) / Log ( 2 ) ) )
)

 

 

 Using FMP9.

 

Outcomes