Skip to content

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

Description

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

Usage

<Expr>$bitwise_leading_zeros()

Value

A polars expression

Examples

library("polars")

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