public static int prevPow2(int x){
  if (x < 1)   throw new IllegalArgumentException("x must be greater or equal 1");
  return (int)Math.pow(2,Math.floor(Math.log(x) / Math.log(2)));
}

public static int prevPow2 ( int x ) { if ( x < 1 ) throw new IllegalArgumentException ( "x must be greater or equal 1" ) ; return ( int ) Math . pow ( 2 , Math . floor ( Math . log ( x ) / Math . log ( 2 ) ) ) ; }
returns the closest power - of - two number less than or equal to x .
