in reply to Most Significant Set Bit
though it looks like puke, it's a single statement. Is there a better performing solution?
I doubt there will be a massively better performing solution but unless you are doing this literally billions of times I'd caution against this sort of code because it is such a maintenance nightmare.
Here's a nice, clean bitwise shift version. Likely much slower but so much more maintainable.
my $z = 256; # input my $m = 0; $m++ while $z >> $m; say $m;
Update: See also Bit::Util::bu_first by salva.
🦛
|
|---|