Set all the bits in given range of a number
Submissions: 496   Accuracy:

53.65%

  Difficulty: Easy   Marks: 2

Given a non-negative number N and two values L and R. The problem is to set all the bits in the range L to R in the binary representation of N.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains three integers N, L and R as input.

Output:
For each test case, set the bits in given range and
print the modified number in new line.

Constraints:
1<=T<=100
1<=N<=232
1<=L<=R<=32

Example:
Input:
2

17 2 3
8 1 2

Output:
23
11

Explanation:

Input : N = 17, L = 2, R = 3
Output : 23
(17)10 = (10001)2
(23)10 = (10111)2
The bits in the range 2 to 3 in the binary
representation of 17 are set.

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

Author: arun03


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.