Re: bit_ffs
"Ruud H.G. van Tol" <[email protected]>
| Newsgroups | gmane.comp.mathematics.pari.devel |
|---|---|
| Message-ID | <[email protected]> |
On 2023-03-30 20:09, Bill Allombert wrote: > On Thu, Mar 30, 2023 at 07:02:34PM +0200, 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 > For the bitxxx functions family in GP, > you can use valuation(x,2) (resp. logint(x,2)) Find first set bit: bit_ffs(n) = valuation(n, 2) Count trailing set bits: bit_cts(n) = valuation(n+1, 2) -- Ruud