master-algorithms-py/source_code/bitwise/swap_in_place.py
2018-06-14 15:50:29 -07:00

23 lines
No EOL
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()