Reverse the bits of a 32-bit unsigned integer n and return the result as an unsigned integer.
Swap the two 16-bit halves, then the 8-bit halves inside each, then 4, 2 and 1. Five mask-and-shift steps reverse all 32 bits.
1function reverseBits(n: number): number {2n = (n >>> 16) | (n << 16);3n = ((n & 0xff00ff00) >>> 8) | ((n & 0x00ff00ff) << 8);4n = ((n & 0xf0f0f0f0) >>> 4) | ((n & 0x0f0f0f0f) << 4);5n = ((n & 0xcccccccc) >>> 2) | ((n & 0x33333333) << 2);6n = ((n & 0xaaaaaaaa) >>> 1) | ((n & 0x55555555) << 1);7return n >>> 0;8}
Swap the 16-bit halves.
Space: play/pause · ←/→: step