Returns true if x represents a power of two. This differs from Integer.bitCount(x) == 1, because Integer.bitCount(Integer.MIN_VALUE) == 1, but Integer#MIN_VALUE is not a power of two.
(int x)
| 97 | |
| 98 | |
| 99 | public static boolean isPowerOfTwo(int x) { |
| 100 | return x > 0 & (x & (x - 1)) == 0; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns 1 if {@code x < y} as unsigned integers, and 0 otherwise. Assumes that x - y fits into |