Reverse the Bit Order of a 32-Bit Device Flag Word
Last updated: November 29, 2026
Quick Overview
A legacy Quest headset reports a 32-bit flag word in the opposite bit order from what the server expects. Reverse the 32 bits of an unsigned integer and return the result.
Meta
November 29, 20260
0
0 solved
A legacy Quest headset reports a 32-bit flag word in the opposite bit order from what the server expects. Reverse the 32 bits of an unsigned integer and return the result.
Appears in Meta screens for Reality Labs and infra-leaning roles where low-level data handling matters. The interviewer looks for clean shifting and masking, plus awareness of how to make it fast if called millions of times.
What the Interviewer Expects
- Treat the input as exactly 32 bits, including leading zeros
- Build the result by shifting in the lowest bit each step
- Explain the divide-and-conquer swap version or a byte lookup table
- Discuss caching when the function is hot
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you optimize this if it is called billions of times?
- Do it with five mask-and-shift steps and no loop.
- How does endianness differ from bit reversal?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: integer x in [0, 2^32). Output: integer whose bit i equals bit (31 - i) of x. Leading zeros of x count, so 1 becomes 2^31. Python ints are unbounded, so mask to 32 bits where needed....
High-Level Design
Loop 32 times: shift the result left by one, OR in the lowest bit of x, shift x right. After 32 iterations every bit has moved to its mirrored position.
For a hot path, swap progressively larger bloc...