check if a number is power of 2 java code example
Example: how to check if a number is a power of 2 java
//create a boolean method that checks if number is a power of 2 by using modulus
public static boolean powerOfTwoGeneral(int n)
{
while(n%2==0)
{
n=n/2;
}
if(n==1)
{
return true;
}
else
{
return false;
}
}