Dsa
Bit Manipulation
Easy
Bit Pair Swapper
You are given an integer n. Write a function to swap every two adjacent bits in the integer. For example, the binary representation of 10 is 1010; swapping every two bits results in 1010, which is still 10. The binary representation of 11 (1011) after swapping becomes 1101 (which is 13).
Input:
A single integer n (0 ≤ n ≤ 10^9)
Output:
The integer resulting from swapping every two adjacent bits.
Example:
Input:
11
Output:
13
Key concepts
bit manipulationswapping
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now