Use bit manipulation to check power of 4 properties.
(n & (n-1)) == 0(n & 0x55555555) != 00x55555555 = 0101...0101 masks even bit positions1class Solution {
2 public boolean isPowerOfFour(int n) {
3 if (n <= 0) return false;
4
5 // Check if power of 2 and bit at even position
6 return (n & (n - 1)) == 0 && (n & 0x55555555) != 0;
7 }
8}