Python Challenges: Reverse the bits of an integer(32 bits unsigned)
Write a Python program to reverse the bits of an integer (32 bits unsigned).
Explanation:
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 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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics