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

sub ispow2 { my $i = shift; while ($i) { if ($i % 2) { return ($i == 1) ? 1 : 0 } $i >>= 1; } return 0; }