Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse Bits in One Byte

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

Your question is Reverse Bits in One Byte. 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 integer n representing an 8-bit unsigned value (0 to 255), return the integer produced by reversing its 8 bits. For example, if the binary form is 00000101, the reversed result is 10100000. The function should return the reversed value as an integer.

Constraints

  • 0 <= n <= 255
  • Treat the input as exactly 8 bits
  • Use integer and bitwise operations

Function Signature

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