Skip to main content

Mojo module

bit

Provides functions for bit manipulation.

You can import these APIs from the bit package. For example:

from bit import count_leading_zeros
from bit import count_leading_zeros

Functions

  • bit_ceil: Computes the smallest power of 2 that is greater than or equal to the input value. Any integral value less than or equal to 1 will be ceiled to 1.
  • bit_floor: Computes the largest power of 2 that is less than or equal to the input value. Any integral value less than or equal to 0 will be floored to 0.
  • bit_not: Performs a bitwise NOT operation on an SIMD vector of integer values.
  • bit_reverse: Reverses the bitpattern of an integer value.
  • bit_width: Computes the minimum number of bits required to represent the integer.
  • byte_swap: Byte-swaps an integer value with an even number of bytes.
  • count_leading_zeros: Counts the number of leading zeros of an integer.
  • count_trailing_zeros: Counts the number of trailing zeros for an integer.
  • is_power_of_two: Checks if the input value is a power of 2.
  • pop_count: Counts the number of bits set in an integer value.
  • rotate_bits_left: Shifts the bits of an input to the left by shift bits (with wrap-around).
  • rotate_bits_right: Shifts the bits of an input to the right by shift bits (with wrap-around).