Reverse Bits

Problem: Reverse Bits

We extract each 32 digits and append to our answer.

Code in Python:

class Solution(object):
    def reverseBits(self, n):
        """
        :type n: int
        :rtype: int
        """
        ans = 0
        for i in xrange(32):
            ans = ans << 1
            ans |= (n >> i) & 1
        return ans

results matching ""

    No results matching ""