w3resource

Python Challenges: Reverse the bits of an integer(32 bits unsigned)

Python Challenges - 1: Exercise-19 with Solution

Write a Python program to reverse the bits of an integer (32 bits unsigned).

Explanation:

Python: Reverse the bits of an integer(32 bits unsigned)

Sample Solution:

Python Code:

def reverse_Bits(n):
        result = 0
        for i in range(32):
            result <<= 1
            result |= n & 1
            n >>= 1
        return result
            
print(reverse_Bits(1234))

Sample Output:

1260388352

Flowchart:

Python Flowchart: Reverse the digits of an integer(32 bits unsigned)

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to reverse the digits of an integer.
Next: Write a Python program to check a sequence of numbers is an arithmetic progression or not.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.