Python code (O(logn))


#1
import math
class Solution:
    # @param A : unsigned integer
    # @return an unsigned integer
    def reverse(self, A):
        out = 0
        i = 31
        while A > 0:
            if (A & 1):
                out += 1 << i
            i -= 1
            A = A >> 1
        return out