Preview:
public boolean isPowerOfFour(int n) {
        // If a number is power of 2, It will have 1 bit at even position and if its a power of 4, 
        // which is not a power of 2 e.g. 128 it will have 1 bit at odd position.

        return (n >0) && ((n &(n-1)) ==0) && ((n & 0xaaaaaaaa) ==0);
        
    }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter