bit
This library contains various helper functions for common bit operations.
Functions
std::bit::popcount
std::bit::popcount
Calculates the number of 1 bits in a given number
x
: The numberreturn
: The number of bits set to 1 inx
std::bit::has_single_bit
std::bit::has_single_bit
Checks if only a single bit is set to 1 in a given number
x
: The numberreturn
: True if there's a single bit set to 1 inx
, false otherwise
std::bit::bit_ceil
std::bit::bit_ceil
Rounds the given number up to the next bigger power of two
x
: The numberreturn
: Next bigger power of two that can fitx
std::bit::bit_floor
std::bit::bit_floor
Rounds the given number down to the next bigger power of two
x
: The numberreturn
: Next smaller power of two
Last updated