Skip to content

Evaluate the number most-significant set bits before seeing an unset bit.

Description

Evaluate the number most-significant set bits before seeing an unset bit.

Usage

<Expr>$bitwise_leading_ones()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(n = c(-1L, 0L, 2L, 1L))
df$with_columns(leading_ones = pl$col("n")$bitwise_leading_ones())
#> shape: (4, 2)
#> ┌─────┬──────────────┐
#> │ n   ┆ leading_ones │
#> │ --- ┆ ---          │
#> │ i32 ┆ u32          │
#> ╞═════╪══════════════╡
#> │ -1  ┆ 32           │
#> │ 0   ┆ 0            │
#> │ 2   ┆ 0            │
#> │ 1   ┆ 0            │
#> └─────┴──────────────┘