Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
A power of two in binary has exactly one set bit. Check that n is positive, then verify n & (n - 1) equals zero. This expression clears the single set bit, leaving zero only for powers of two.
Powers of two are the only positive integers with a single 1-bit, so n & (n - 1) which clears the lowest set bit will produce zero exclusively for them.
Updated Feb 2026