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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Bit manipulation
Masks and shifts
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported