


There is a song concert going to happen in the city. The price of each ticket is equal to the number obtained after reversing the bits of a given 32 bits unsigned integer ‘n’.
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains a single unsigned integer ‘N’ whose bits are to be reversed.
Output Format :
For each test case, print the number obtained after reversing the bits.
Print the output for each test case in a separate line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
2
0
12
0
805306368
For the first test case :
Since the given number N = 0 is represented as 00000000000000000000000000000000 in its binary representation. So after reversing the bits, it will become 00000000000000000000000000000000 which is equal to 0 only. So the output is 0.
For the second test case :
Since the given number N = 12 is represented as 00000000000000000000000000001100 in its binary representation. So after reversing the bits, it will become 0110000000000000000000000000000, which is equal to 805306368 only. So the output is 805306368.
2
6
4
1610612736
536870912
For the first test case :
Since the given number N = 6 is represented as 00000000000000000000000000000110 in its binary representation. So after reversing the bits, it will become 01100000000000000000000000000000, which is equal to 1610612736.
For the second test case :
Since the given number N = 4 is represented as 00000000000000000000000000000100 in its binary representation. So after reversing the bits, it will become 0010000000000000000000000000000, which is equal to 536870912 only.
The expected time complexity is O(log(n)).
1 <= T <= 10
0 <= N <= 2^32
Time Limit: 1 sec
Swap the leftmost and the rightmost bits of the given number.
Approach:
Algorithm:
O(1).
Since we iterate over 16 bits only, which will take constant time. So the overall time complexity will be O(1).
O(1).
Since constant space is being used. So overall space complexity will be O(1).