MCPcopy Create free account
hub / github.com/antlr/codebuff / isPowerOfTwo

Method isPowerOfTwo

output/java_guava/1.4.19/IntMath.java:99–101  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

log2Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected