Swap bits
Submissions: 1355   Accuracy:

50.76%

  Difficulty: Easy   Marks: 2

Given a number x and two positions (from right side) in binary representation of x, write a program that swaps n bits at given two positions and returns the result.

Input:

The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is X, P1, P2 and N. X is a number, P1 and P2 is two given position and swaps N number of bits at given two position.

Output:

Print the result.

Constraints:

1 ≤ T ≤ 15
1 ≤ X ≤ 200
0 ≤ P1 < P2 ≤ 8
1 ≤ N ≤ 5

Example:

Input:
2
47 1 5 3
28 0 3 2

Output:
227
7

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.