#C1034. Pairwise Bit Swap

    ID: 39534 Type: Default 1000ms 256MiB

Pairwise Bit Swap

Pairwise Bit Swap

You are given a non-negative integer n. Your task is to swap every pair of adjacent bits in its binary representation. In other words, for every even position, swap the bit with its adjacent bit at odd position.

For example, consider n = 23:

  • Binary representation of 23 is 10111.
  • Swapping adjacent bits gives 101011, which is the binary representation of 43.

You can make use of the bit masks in your solution. The mask for even-indexed bits is given by \(0xAAAAAAAA\) and for odd-indexed bits by \(0x55555555\). After isolating the bits with these masks, shift them appropriately and then combine to get the final result.

Note that the bits are numbered from right-to-left starting with index 0.

inputFormat

The input consists of a single line containing a non-negative integer n (0 ≤ n ≤ 231 - 1), where the bits will be swapped pairwise.

outputFormat

Output the resulting integer after swapping each pair of adjacent bits.

## sample
23
43