We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bb6385e commit db1f33eCopy full SHA for db1f33e
src/test/java/com/thealgorithms/bitmanipulation/PowerOfFour.java
@@ -0,0 +1,16 @@
1
+package bitmanipulation;
2
+
3
+public class PowerOfFour {
4
+ public static boolean isPowerOfFour(int n) {
5
+ // A power of 4 has only one bit set and that bit is at an even position
6
+ return n > 0 && (n & (n - 1)) == 0 && (n & 0x55555555) != 0;
7
+ }
8
9
+ public static void main(String[] args) {
10
+ int num = 64; // change to test other numbers
11
+ if (isPowerOfFour(num))
12
+ System.out.println(num + " is a power of 4.");
13
+ else
14
+ System.out.println(num + " is NOT a power of 4.");
15
16
+}
0 commit comments