http://www.perlmonks.org?node_id=142122

larryk has asked for the wisdom of the Perl Monks concerning the following question:

I understand the binary representation of such a number will be a 1 with zero or more trailing 0s so with that in mind I rather sheepishly offer the following:
sub is_power_of_2 { my $number = shift; sprintf('%b',$number) =~ /^10*$/ ? 1 : 0; }
What is the most efficient way to shift that 1 to the other end so I can compare the value to 1 instead of using this horrible regex. Or is there a quicker way?