http://www.matrix67.com/blog/archives/3985

 

unsigned int v;  // find the number of trailing zeros in 32-bit v
int r;           // result goes here
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];

 

http://graphics.stanford.edu/~seander/bithacks.html

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-02-19
  • 2021-05-16
猜你喜欢
  • 2022-12-23
  • 2021-08-29
  • 2021-06-15
  • 2021-10-29
  • 2021-11-17
  • 2021-08-31
相关资源
相似解决方案