Skip to content

Instantly share code, notes, and snippets.

@syzdek
Created March 5, 2009 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syzdek/74452 to your computer and use it in GitHub Desktop.
Save syzdek/74452 to your computer and use it in GitHub Desktop.
reverses the bits in a 32 bit word
n = ((n >> 1) & 0x55555555) | ((n << 1) & 0xaaaaaaaa);
n = ((n >> 2) & 0x33333333) | ((n << 2) & 0xcccccccc);
n = ((n >> 4) & 0x0f0f0f0f) | ((n << 4) & 0xf0f0f0f0);
n = ((n >> 8) & 0x00ff00ff) | ((n << 8) & 0xff00ff00);
n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment