Problems > Swap Neighbouring Bits

Swap Neighbouring Bits

Difficulty: 1300 2000 ms 128 MB

bitwise

Swap every even-indexed bit of N with the odd-indexed bit just above it (bit 0 with bit 1, bit 2 with bit 3, ...). Print the result.

Input: one integer N.

Output: N with adjacent bit pairs swapped.

Constraints:

  • 0 ≤ N < 262

Sample Tests

Input 1
10
Output 1
5
Input 2
23
Output 2
43

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.