Skip to main content



Provides functions for bit manipulation.

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

from math.bit import ctlz


  • ctlz: Counts the number of leading zeros of an integer.
  • cttz: Counts the number of trailing zeros for an integer.
  • select: Performs an elementwise select based on the input condition value.
  • bitreverse: Reverses the bitpattern of an integral value.
  • bswap: Byte-swaps a value.
  • ctpop: Counts the number of bits set in a value.
  • bit_not: Performs a bitwise NOT operation on an integral.
  • bit_and: Performs a bitwise AND operation.
  • bit_length: Computes the number of digits required to represent the integer.