Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def reverseBits(self, n: int) -> int:
- mask=1
- res=0
- for i in range(32):
- res=res<<1
- if mask & n:
- res=res | 1
- mask=mask<<1
- return res
- ```
- Here we are reversing the number for 32 bits. Every time we are updating the mask annd res when necessary.
- Consider the condtion if mask & n which tells that whethere there is a 1 bit at pos log 2 (mask).
- If so we add 1 to res else we do nothing
- ```
Add Comment
Please, Sign In to add comment