BigIntegerMath isPowerOfTwo() function | Guava | Java
The method isPowerOfTwo(BigInteger x) of Guava’s BigIntegerMath class returns true if x represents a power of two.
Syntax:
public static boolean isPowerOfTwo(BigInteger x)
Parameters: This method takes the BigInteger number x as parameter which is to be checked.
Return Value: This method returns true if x is a power of two.
Below examples illustrates the BifIntegerMath.isPowerOfTwo() method:
Example 1:
// Java code to show implementation of // isPowerOfTwo(BigInteger x) method of // Guava's BigIntegerMath class import java.math.*; import com.google.common.math.BigIntegerMath; class GFG { // Driver code public static void main(String args[]) { BigInteger a1 = BigInteger.valueOf(63); // Using isPowerOfTwo(BigInteger x) method // of Guava's BigIntegerMath class if (BigIntegerMath.isPowerOfTwo(a1)) System.out.println(a1 + " is power of 2"); else System.out.println(a1 + " is not power of 2"); BigInteger a2 = BigInteger.valueOf(1024); // Using isPowerOfTwo(BigInteger x) method // of Guava's BigIntegerMath class if (BigIntegerMath.isPowerOfTwo(a2)) System.out.println(a2 + " is power of 2"); else System.out.println(a2 + " is not power of 2"); } } |
chevron_right
filter_none
Output:
63 is not power of 2 1024 is power of 2
Example 2:
// Java code to show implementation of // isPowerOfTwo(BigInteger x) method of // Guava's BigIntegerMath class import java.math.*; import com.google.common.math.BigIntegerMath; class GFG { // Driver code public static void main(String args[]) { BigInteger a1 = BigInteger.valueOf(1); // Using isPowerOfTwo(BigInteger x) method // of Guava's BigIntegerMath class if (BigIntegerMath.isPowerOfTwo(a1)) System.out.println(a1 + " is power of 2"); else System.out.println(a1 + " is not power of 2"); BigInteger a2 = BigInteger.valueOf(567); // Using isPowerOfTwo(BigInteger x) method // of Guava's BigIntegerMath class if (BigIntegerMath.isPowerOfTwo(a2)) System.out.println(a2 + " is power of 2"); else System.out.println(a2 + " is not power of 2"); } } |
chevron_right
filter_none
Output:
1 is power of 2 567 is not power of 2
Recommended Posts:
- BigIntegerMath log2() function | Guava | Java
- BigIntegerMath log10() function | Guava | Java
- BigIntegerMath floorPowerOfTwo() function | Guava | Java
- BigIntegerMath sqrt() function | Guava | Java
- BigIntegerMath binomial() function | Guava | Java
- BigIntegerMath divide() function | Guava | Java
- BigIntegerMath ceilingPowerOfTwo() function | Guava | Java
- BigIntegerMath factorial() function | Guava | Java
- Java Guava | isPowerOfTwo() method IntMath Class
- Java Guava | isPowerOfTwo(long x) of LongMath Class with Examples
- BigIntegerMath Class | Guava | Java
- Ints contains() function | Guava | Java
- Ints max() function | Guava | Java
- Ints min() function | Guava | Java
- Ints concat() function | Guava | Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



