Last Updated: 27 Aug, 2025

Toggle Bits From MSB

Easy

Problem statement

You are given a non-negative integer 'n'. Your task is to toggle all the bits of this number from the Most Significant Bit (MSB) downwards, including the MSB itself.

The Most Significant Bit (MSB) is the leftmost '1' in the binary representation of the number. For example, if the number is 10 (binary 1010), its MSB is the first '1'. Toggling from the MSB downwards would change 1010 to 0101 (which is 5 in decimal).


Input Format:
A single line containing an integer 'n'.


Output Format:
Print a single integer representing the result after toggling the bits.


Note:
Toggling a bit means changing a 0 to a 1, and a 1 to a 0.
The input 'n' is a non-negative integer.
For the input n=0, its binary representation is 0. The MSB is considered to be at the 0th position. Toggling it results in 1.