Math.clz32()
The Math.clz32()
function returns the number of leading zero bits in the 32-bit binary representation of a number.
Syntax
Math.clz32(x)
Parameters
x
- : A number.
Return value
The number of leading zero bits in the 32-bit binary representation of x
.
Description
clz32
is short for CountLeadingZeros32.
If x
is not a number, it will be converted to a number first, then converted to a 32-bit unsigned integer.
If the converted 32-bit unsigned integer is 0
, 32
is returned, because all bits are 0
. If the most significant bit is 1
(i.e. the number is greater than or equal to 231), 0
is returned.
This function is particularly useful for systems that compile to JS, like Emscripten.