Given a int suppose 5, whose binary representation is 101, we need to flip the bit which will be 010, which will be 2 : <p>I am converting the given int to binary represention which is string, and then traversing the string and changing each char/bit in string and then converting back to required int.</p>

<p>Myquestion is, is there a mathematical or better way to do this?</p>
