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
Count the number of significant bits in the number, then create a mask of all 1s with that length using (1 << bits) - 1. XOR the number with the mask to flip every bit within the significant range.
XOR with a mask of all 1s flips each bit (0 becomes 1, 1 becomes 0), producing the complement within the number's actual bit width rather than the full 32-bit width.
Updated Feb 2026