2018-06-14 15:50:29 -07:00

23 lines
298 B
Python
Executable File

#!/usr/bin/env python
__author__ = "bt3"
'''
swapping values in place without extra memory
'''
def swap_bit(a, b):
'''
>>> swap_bit(14, 73)
(73, 14)
'''
a = a^b
b = a^b
a = a^b
return a, b
if __name__ == '__main__':
import doctest
doctest.testmod()