Swap Adjacent Bit Pairs Problem Statement
Given an integer N
, your task is to compute the number that results from swapping each even position bit of N
's binary representation with its adjacent odd bit to the right. Consider the least significant bit as an odd position.
Example:
Input:
N = 45
Output:
30
Explanation:
The binary representation of 45
is 101101
. After swapping each even bit with its adjacent odd bit to the right, it results in 011110
, which is the integer 30
.
Constraints:
1 ≤ T ≤ 105
1 ≤ N ≤ 109
- Time Limit: 1 sec
AnswerBot
4d
Swap each even position bit of an integer with its adjacent odd bit to the right in binary representation.
Iterate through the binary representation of the integer and swap adjacent bits at even positi...read more
Help your peers!
Add answer anonymously...
Top Juniper Networks Staff Engineer interview questions & answers
Popular interview questions of Staff Engineer
>
Juniper Networks Staff Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app