Reversed Bits integer
- Convert to a string
- Reverse the string
- Convert the reversed string to integer
- Get the
i
(0....31) bit of input - Replace the
bit
in31 - i
bit of output
Approach
class Solution:
def reverseBits(self, n: int) -> int:
res = 0
for i in range(32):
bit = (n >> i) & 1
res = res | (bit << (31 - i))
return res