Dsa
Bit Manipulation
Easy
The Nibble Swap Protocol
A 'nibble' is a 4-bit aggregation. A 32-bit unsigned integer contains 8 nibbles. Your task is to reverse the order of these nibbles. The nibble at the least significant position (bits 0-3) should move to the most significant position (bits 28-31), the second nibble (bits 4-7) moves to the second-to-last (bits 24-27), and so on.
Input: A single 32-bit unsigned integer.
Output: The integer resulting from the nibble reversal.
Example:
Input: 15
Explanation:
15 in binary is 0000...00001111.
Only the first nibble (0) is 1111 (0xF), others are 0000 (0x0).
After reversal, the 8th nibble is 0xF and others are 0x0.
0xF0000000 in decimal is 4026531840.
Output: 4026531840
Key concepts
bit_manipulationdata_formatting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now