Ruud H.G. van Tol on Thu, 30 Mar 2023 19:56:22 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: bit_ffs



On 2023-03-30 19:43, Ruud H.G. van Tol wrote:
On 2023-03-30 19:02, Ruud H.G. van Tol wrote:
Might be interesting to add:

https://en.wikipedia.org/wiki/Find_first_set
https://www.man7.org/linux/man-pages/man3/ffs.3.html
https://www.go4expert.com/articles/builtin-gcc-functions-builtinclz-t29238/

Or are those too low-level?

bit_ffs, bit_ctz

Count trailing set bits:

bit_cts(n) = logint( 1 + bitand(n, bitneg(n) - 1), 2 )

Similar:

  bit_cts(n) = logint( bitand( bitneg(n), n + 1 ), 2 )

-- Ruud