Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse Bits of Integer

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Reverse Bits of Integer. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an unsigned 32-bit integer n, return the unsigned integer produced by reversing its bit order. Bit 0 becomes bit 31, bit 1 becomes bit 30, and so on. Implement a function that operates on exactly 32 bits.

Constraints

  • 0 <= n <= 2^32 - 1
  • Treat n as an unsigned 32-bit integer
  • The solution must reverse exactly 32 bits

Function Signature

def reverse_bits(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output