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
First check if n is a power of two using n & (n - 1) === 0. Then verify the single set bit is at an even position (bit 0, 2, 4, ...) by ANDing with the mask 0x55555555 which has 1s at all even bit positions.
Powers of four are powers of two where the set bit falls at an even index (4^0=bit 0, 4^1=bit 2, 4^2=bit 4). The 0x55555555 mask isolates exactly those positions.
Updated Feb 2026