What is Math.clz32() in JavaScript?
Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains a clz32() function, which is used to compute the number of leading zeros in a 32-bit binary representation of a specified number. clz stands for count leading zeros.
Syntax
Math.clz32(param);
Parameter
param: This is the input value of theNumbertype for which we want to find theclz32().
Numberin JavaScript is a 64-bit double-precision value that is the same asdoublein C# or Java.
If
paramis not a number, it will be converted to a number first, then converted to a 32-bit unsigned integer.
Return value
Number: It returns a count of leading zeros whenparamis represented in a 32-bit representation. It is of theNumbertype.
Example
console.log("clz32(-20) = " + Math.clz32(-20));console.log("clz32(20) = " + Math.clz32(20));console.log("clz32(0) = " + Math.clz32(0));console.log("clz32(2.34) = " + Math.clz32(2.34));console.log("clz32(-2.34) = " + Math.clz32(-2.34));