Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 344 Bytes

is-power-of-two.md

File metadata and controls

16 lines (14 loc) · 344 Bytes
title description author tags
Is Power Of Two
Checks if a number is a power of two
Mcbencrafter
math,number,bit,power-of-two
public static boolean isPowerOfTwo(int number) {
    return (number > 0) && ((number & (number - 1)) == 0);
}

// Usage:
int number = 16;
System.out.println(isPowerOfTwo(number)); // true (2^4)