ArithmeticUtils { public static boolean isPowerOfTwo(long n) { return (n > 0) && ((n & (n - 1)) == 0); } private  ArithmeticUtils(); static int addAndCheck(int x, int y); static long addAndCheck(long a, long b); @Deprecated static long binomialCoefficient(final int n, final int k); @Deprecated static double binomialCoefficientDouble(final int n, final int k); @Deprecated static double binomialCoefficientLog(final int n, final int k); @Deprecated static long factorial(final int n); @Deprecated static double factorialDouble(final int n); @Deprecated static double factorialLog(final int n); static int gcd(int p, int q); static long gcd(final long p, final long q); static int lcm(int a, int b); static long lcm(long a, long b); static int mulAndCheck(int x, int y); static long mulAndCheck(long a, long b); static int subAndCheck(int x, int y); static long subAndCheck(long a, long b); static int pow(final int k,
                          final int e); @Deprecated static int pow(final int k, long e); static long pow(final long k,
                           final int e); @Deprecated static long pow(final long k, long e); static BigInteger pow(final BigInteger k, int e); static BigInteger pow(final BigInteger k, long e); static BigInteger pow(final BigInteger k, BigInteger e); @Deprecated static long stirlingS2(final int n, final int k); static boolean isPowerOfTwo(long n);  }
@Test public void testIsPowerOfTwo() { final int n = 1025; final boolean[] expected = new boolean[n]; Arrays.fill(expected, false); for (int i = 1; i < expected.length; i *= 2) { expected[i] = true; } for (int i = 0; i < expected.length; i++) { final boolean actual = ArithmeticUtils.isPowerOfTwo(i); Assert.assertTrue(Integer.toString(i), actual == expected[i]); } }