Reverse Bits

Easy · Bit Manipulation · about 10 minutes

Asked at Apple, Amazon, Google, Microsoft, Qualcomm, NVIDIA, AMD, Waymo, Broadcom, Epic Games, SpaceX, xAI, Mistral AI, Rivian, Samsung, Sony, Micron, Arm.

Reverse the bits of a 32-bit integer n (given here as a non-negative value) and return the result as a signed 32-bit integer — the bit pattern is what matters, so a result with the top bit set is negative.