1 ) Toggle k - th bit by doing n ^ ( 1 << k ) 2 ) Toggle all bits of the modified number
temp = bin ( n ^ ( 1 << k ) ) [ 2 : ] NEW_LINE ans = " " NEW_LINE for i in temp : NEW_LINE INDENT if i == '1' : NEW_LINE INDENT ans += '0' NEW_LINE DEDENT else : NEW_LINE INDENT ans += '1' NEW_LINE DEDENT DEDENT return int ( ans , 2 ) NEW_LINE