Help for this page

Select Code to Download


  1. or download this
    sub is_power_of_2 {
      return 0 unless $_[0]>0; # to avoid log error
      log($_[0])/log(2) - int(log($_[0])/log(2)) ? 0 : 1 
    }
    
  2. or download this
    sub is_power_of_2 {
      local $_ = $_[0];
    ...
      return if ($_ - int($_));
      1;
    }