turn off the first set bit(1 bit) of a number N.

N-1 will have all bits reversed before and including the first bit set.

N &amp (N-1) will turn off the first set bit.

N &amp (N-1)

int n = 20;
// prints "10100"
System.out.println(Integer.toBinaryString(n));
// n-1 will have all bits reversed before and including the first bit set
// n & (n-1) will turn off the first set bit
n = n & (n-1);
// prints "10000";
System.out.println(Integer.toBinaryString(n));

Check if N is a power of 2 or not.

if N is a power of 2, N-1 will have all 1s, except that the 1 bit of N will be converted to 0.

so, if N is a power of 2, then (N &amp (N-1) == 0)

int n1 = 20;
int n2 = 32;
// n = power of 2 will have one 1 followed by all 0s.
// n-1 will have one 0 followed by all 1s.
// n & (n-1) is 0 for power of 2, and 1 otherwise.
// prints false, becase 20 is not a power of 2.
System.out.println((n1 & (n1-1)) == 0);
// prints true, because 32 is a power of 2.
System.out.println((n2 & (n2-1)) == 0);

Check if N is a power of 4 or not.

check that N is a power of 2(from above)

check that there are a total of even 0s in the binary representation of N.