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
XOR start and goal to highlight the bits that differ. Count the set bits in the XOR result using Brian Kernighan's algorithm. Each set bit represents one required flip.
XOR marks exactly the positions where the two numbers differ, and the count of those 1-bits equals the minimum number of single-bit flips needed to convert one number to the other.
Updated Feb 2026