trailingZeros

trailingZeros(integer x) → integer zeros

Returns the number of trailing 0 bits of the integer x*, that is, the bits before its first 1 bit, starting from the least significant bit. It is the position of the lowest 1 bit, or equivalently the exponent of the largest power of 2 that divides *x.

Returns 64 when x is 0, since no bit is 1. The function also works on big integers.

trailingZeros(0)   // 64 : no bit is 1
trailingZeros(1)   // 0
trailingZeros(8)   // 3  : 1000 in binary
trailingZeros(12)  // 2  : 1100 in binary
trailingZeros(-1)  // 0  : all bits are 1
Math.trailingZeros(0)   // 64 : no bit is 1
Math.trailingZeros(1)   // 0
Math.trailingZeros(8)   // 3  : 1000 in binary
Math.trailingZeros(12)  // 2  : 1100 in binary
Math.trailingZeros(0)   # 64 : no bit is 1
Math.trailingZeros(1)   # 0
Math.trailingZeros(8)   # 3  : 1000 in binary
Math.trailingZeros(12)  # 2  : 1100 in binary
Parameters
Return
Note