Problems > Swap Neighbouring Bits > Editorial

Swap Neighbouring Bits — Solution & Editorial

Back to the Problem

Mask the even bits (0x5555...) and odd bits (0xAAAA...), shift the first left and the second right, OR together.

Complexity: O(1)