Reverse the Bit Order of a 32-Bit Sensor Reading

Last updated: November 29, 2026

Quick Overview

A temperature sensor in a fulfillment center sends 32-bit readings with the bits in reverse order. Given an unsigned 32-bit integer, return the integer whose bits are in the opposite order.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


A temperature sensor in a fulfillment center sends 32-bit readings with the bits in reverse order. Given an unsigned 32-bit integer, return the integer whose bits are in the opposite order.

A short Amazon online assessment item that checks comfort with shifts and masks. Graders look for a correct fixed-width loop and, in follow-up, for a byte lookup table when the function is called millions of times.

What the Interviewer Expects
  • Loops exactly 32 times, not until the number is 0
  • Builds the result with shift and OR
  • Keeps the result within 32 bits
  • Mentions the lookup-table or divide-and-conquer speedup
  • Tests 0 and all ones
Key Topics to Cover
bit reversal
shifts and masks
lookup tables
fixed width integers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you speed this up if called a billion times?
  • Do it with five mask-and-swap steps instead of a loop.
  • How does this differ in a language with signed 32-bit integers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: integer 0 <= x < 2^32. Output: the 32-bit integer with bit i of x moved to bit 31 - i. Leading zeros count, so 1 becomes 2^31....

High-Level Design

Process 32 positions: shift the result left by one, OR in the lowest bit of x, then shift x right. Stopping when x becomes 0 would be wrong because the remaining zeros still need to push the result to...


Submit Your Answer
Markdown supported