Toggle all the bits in the binary representation of a number

Given a number N, toggle all the bits to the right of the most significant bit (MSB) bit (and including MSB also) in the binary representation of the number.
Input will be an integer N.
Solution will be an integer having Ns all bits inverted after the MSB.

Please check out the video which explains the solution to this problem.


Please try solving this problem before jumping on the solution

Click to learn






Subscribe for more updates



Preparing for interviews? IDeserve team is here to help.




Hone your coding skills!




AngryNerds Practice platform »

Contribution

  • Sincere thanks from IDeserve community to Saurabh Kumar for compiling current post.

    Saurabh Kumar

    Ninja Programmer