476. Number Complement

Practice Number Complement for free on NudgeCode: Easy, Bit Manipulation pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Write the positive integer num in binary without leading zeros, flip every bit of that form (0 becomes 1 and 1 becomes 0), and return the resulting integer. Only the bits from the highest 1 down to bit 0 are flipped, not a fixed 32-bit width.

Example

num = 5  ->  2   (101 -> 010)
num = 1  ->  0   (1 -> 0)

Constraints