Add 1 to a given number | Python3 code to add 1 one to a given number ; Flip all the set bits until we find a 0 ; flip the rightmost 0 bit ; Driver program
def addOne ( x ) : NEW_LINE INDENT m = 1 ; NEW_LINE while ( x & m ) : NEW_LINE INDENT x = x ^ m NEW_LINE m <<= 1 NEW_LINE DEDENT x = x ^ m NEW_LINE return x NEW_LINE DEDENT n = 13 NEW_LINE print addOne ( n ) NEW_LINE