IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

bit

Provides functions for bit manipulation.

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

from std.bit import count_leading_zeros

Functions​

  • ​bit_not: Performs a bitwise NOT operation on an SIMD vector of integer values.
  • ​bit_reverse: Element-wise reverses the bitpattern of a SIMD vector of integer values.
  • ​bit_width: Computes the minimum number of bits required to represent each element of a SIMD vector of integer values.
  • ​byte_swap: Byte-swaps a SIMD vector of integer values with an even number of bytes.
  • ​count_leading_zeros: Counts the per-element number of leading zeros in a SIMD vector.
  • ​count_trailing_zeros: Counts the per-element number of trailing zeros in a SIMD vector.
  • ​log2_ceil: Returns the ceiling of the base-2 logarithm of an integer value.
  • ​log2_floor: Returns the floor of the base-2 logarithm of an integer value.
  • ​next_power_of_two: Computes the smallest power of 2 that is greater than or equal to the input value for each element of a SIMD vector. Any integral value less than or equal to 1 will be ceiled to 1.
  • ​pop_count: Counts the number of bits set in a SIMD vector of integer values.
  • ​prev_power_of_two: Computes the largest power of 2 that is less than or equal to the input value for each element of a SIMD vector. Any integral value less than or equal to 0 will be floored to 0.
  • ​rotate_bits_left: Shifts bits to the left by shift positions (with wrap-around) for each element of a SIMD vector.
  • ​rotate_bits_right: Shifts bits to the right by shift positions (with wrap-around) for each element of a SIMD vector.