FunctionRacerProblemsRace

Number Complement

EasyBitsPython, JavaScript, TypeScript, Java, C++

Write num in binary without leading zeros, flip every bit (0 becomes 1, 1 becomes 0), and return the number the flipped bits represent.

Example 1

num 5
returns 2

101 flips to 010, which is 2.

Example 2

num 1
returns 0

1 flips to 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems