Toggle All Bits After MSB (Including MSB)
E · easyP · Verified PYQmath
Problem
Given positive integer N, convert to binary and toggle ALL bits (including MSB). Print resulting integer.
Constraints
1<=N<=100
Example
Input
10
Output
5
k = (1 << (floor(log2(N))+1)) - 1. Answer = N XOR k.
10 = 1010 binary. Toggle all 4 bits = 0101 = 5.