Comment on page

# bit

This library contains various helper functions for common bit operations.

Calculates the number of 1 bits in a given number

`x`

: The number`return`

: The number of bits set to 1 in`x`

fn popcount(u128 x);

Checks if only a single bit is set to 1 in a given number

`x`

: The number`return`

: True if there's a single bit set to 1 in`x`

, false otherwise

fn has_single_bit(u128 x);

Rounds the given number up to the next bigger power of two

`x`

: The number`return`

: Next bigger power of two that can fit`x`

fn bit_ceil(u128 x);

Rounds the given number down to the next bigger power of two

`x`

: The number`return`

: Next smaller power of two

fn bit_floor(u128 x);

Last modified 8mo ago