in reply to How can I tell if a number is a power of 2?
I might try table lookup.
sub is_power_of_2 { my $n = shift; 1 == grep { $_ == $n } ( 1 2 4 8 ... ) }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How can I tell if a number is a power of 2?
by Cine (Friar) on Jan 29, 2002 at 00:25 UTC |