in reply to next power of two

Or a faster version without using any regexp
sub next_power_of_two ($) { my %s; @s{1..$_[0]} = (); return substr(%s,1+index(%s,'/')); } print next_power_of_two(257);

Replies are listed 'Best First'.
Re^2: next power of two
by BrowserUk (Patriarch) on Sep 11, 2011 at 13:05 UTC

    About 50x faster still :)

    sub b{ my %s; keys %s = shift; undef $s{1}; substr %s, 1+index( %s,'/' ); }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      ...and here is the fastest :-)

      sub next_power_of_two {2 << log($_[0]) / log(2)}