Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How can I tell if a number is a power of 2?

by c-era (Curate)
on Jan 29, 2002 at 01:13 UTC ( #142190=note: print w/ replies, xml ) Need Help??


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

How about this one?

sub is_power_of_2{ $num = shift; $num2 = 1; while ($num>$num2){ $num2=$num2<<1; } return ($num^$num2)?0:1; }


Comment on Re: How can I tell if a number is a power of 2?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://142190]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-09-23 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls