in reply to How can I tell if a number is a power of 2?

err, I have no idea how this would benchmark, but couldn't you do
return ! $number % 2;
You'd pay a penalty in the calculation, but by the time you get done with sprintf, pattern matching, and a conditional I think the gap would be a lot closer.

Originally posted as a Categorized Answer.

Replies are listed 'Best First'.
Re: Re: How can I tell if a number is a power of 2?
by VSarkiss (Monsignor) on Jan 28, 2002 at 23:16 UTC

    Oops! You're testing whether $number is odd or even, not whether it's a power of 2.