The Math.clz32() function returns the number of leading zero bits in the 32-bit binary representation of a number.
clz32
is short for Count Leading Zeroes 32.
Math.clz32(x) // x is a number.
If x is not a number, then 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, then return 32, because all bits are 0.
let a = Math.clz32(1); console.log(a);/*from www . ja v a 2 s . c o m*/ a = Math.clz32(1234); console.log(a); a = Math.clz32(); console.log(a); a = Math.clz32(true); console.log(a); a = Math.clz32(3.5); console.log(a); a = 32776; // 00000000000000001000000000001000 (16 leading zeros) Math.clz32(a); // 16 a = ~32776; // 11111111111111110111111111110111 (32776 inversed, 0 leading zeros) Math.clz32(a); // 0 (this is equal to how many leading one's there are in a)