Is An Integer A Power Of Two?
A short bitwise check in Java
Java:
boolean power2(int x) {
return x != 0 && (x & (x - 1)) == 0;
}
A power of two must be greater than zero.
A short bitwise check in Java
Java:
boolean power2(int x) {
return x != 0 && (x & (x - 1)) == 0;
}
A power of two must be greater than zero.