Ruud H.G. van Tol on Fri, 31 Mar 2023 17:25:41 +0200

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

Re: bit_ffs

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:

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