bit_manipulation.xor_swap_two_integers

Functions

xor_swap(→ tuple[int, int])

Swap two integers using bitwise XOR operation and return the swapped values.

Module Contents

bit_manipulation.xor_swap_two_integers.xor_swap(a: int, b: int) tuple[int, int]

Swap two integers using bitwise XOR operation and return the swapped values.

>>> xor_swap(5, 10)
(10, 5)
>>> xor_swap(0, 0)
(0, 0)
>>> xor_swap(-1, 1)
(1, -1)
>>> xor_swap(123, 456)
(456, 123)
>>> xor_swap(12345, 54321)
(54321, 12345)