how to check if a number is a power of 2 java

Solutions on MaxInterview for how to check if a number is a power of 2 java by the best coders in the world

showing results for - "how to check if a number is a power of 2 java"
Vincenzo
28 Feb 2016
1 //create a boolean method that checks if number is a power of 2 by using modulus
2public static boolean powerOfTwoGeneral(int n)
3 {
4 while(n%2==0)
5 {
6 n=n/2;
7 }
8 if(n==1)
9 {
10 return true;
11 }
12 else
13 {
14 return false;
15 }
16 }
17 
18
Mia
08 Sep 2020
1boolean result = number > 0 && ((number & (number - 1)) == 0);
queries leading to this page
java powerjava determine power of 2java get power of 2 of inthow to check if a number is a power of 2 javacheck if number is power of 2 in javapower a two number in javajava to check if the number is power of 2how to check if a power of 2 java 2 power 3 in javapower of javapow 2 javapower of three javahow to check if a number is to the power of another number javacheck if power of 2 javaif is a power of 2 javareturn true if given integer is power of 2 java programjava program create a method to check if a number is a power of two or notjava to the power ofhow to see if a number is power of 2 java2 to the power n in javacheck for power of 2 javato the power 2 in javamath to the power of 2 javapower of 10 in javagiven an integer n 2c write a function to determine if it is a power of two java 10 to the power of3 power of 2 java functionpower of 2 in javacheck if the number is power of 2 in java2 power 4 in javacheck whether given number is power of 2 or not next power javajava power of 3is power of javapower of 2 program in javajava power of 2 operatorjava power of 2 without math powpower of two javajava to the power of 2calculate power of 2 javajava power operatorjava power of 2checking if a number is a power of 3 javajava check if num pow of 2how to check a number is power of 2 javacheck if number is a power of 2 java2 power 10 in javajava using to power of 10 efind power of 2 in javahow to use 2 power n in javahow to show power of in javajava math power of 3check if number is power of 2 javajava program to check power of 2how to take power of 2 in javahow to code a number to the power of two in javajava 2 to the power of ijava program to check whether number is power of two or notjava is power of 2power in javapower of 2 javapower of 2 in javahow to get power of 10 in javahow to make power two in javapower of two numbers in javajava power of how to check if number is power of 2 javajava return power of 2 numberspower of 2 3 in javapower 2 javahow to find the no is power of 2 code in javahow to do 2 power something in javapower of 4 in javato the power 2 javapower javajava 2 to the powerwrite a program to determine if a number is power of 2 or not in javajava power of 2 programpower 2 in javacheck if a number is a power of 2 in javapower of 2 power 3 in javapower of 2 in javajava check if number is power of 2power of two in javacheck if number is power of 10 javashortest way to check if a number is power of 2 java2 power n in javajava 2 power ngiven an integer n 2c check if the number is power of 2 or not in javafinds out if a number is a power of two javacheck if power of 2 in javato the power of java 2f 2f method to check if x is power of 2 in javacheck if a number is power of 2 javais power of two in javajava check power of 2 return true if given integer is power of 2 java programpower of in javajava math pow of 2take power 2 javahow to know if a number is a power of 2 java2 to power of 2 in javax power 2 in javajava power of 10java power of 2 methodcheck power of 2 in javafind is a number is a power of another number javainteger is a power of two javapower operator in javahow to check it is power of 2 in javacreate a method to check if a number is a power of two or not in javacheck if number is power of 4 javapower of three in javajava math power of 2java power 2how to check if a number is a power of 2 java