Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created December 25, 2018 02:29
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 kunigami/1a5efcf3a51008ae9b2952ee00824a8a to your computer and use it in GitHub Desktop.
Save kunigami/1a5efcf3a51008ae9b2952ee00824a8a to your computer and use it in GitHub Desktop.
unsigned int v;
int r;
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment