Add 1 to a given number | C # code to add one to a given number ; Flip all the set bits until we find a 0 ; flip the rightmost 0 bit ; Driver code
using System ; class GFG { static int addOne ( int x ) { int m = 1 ; while ( ( int ) ( x & m ) == 1 ) { x = x ^ m ; m <<= 1 ; } x = x ^ m ; return x ; } public static void Main ( ) { Console . WriteLine ( addOne ( 13 ) ) ; } }