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.

clz32() function

Syntax

Math.clz32(param);

Parameter

  • param: This is the input value of the Number type for which we want to find the clz32().

Number in JavaScript is a 64-bit double-precision value that is the same as double in C# or Java.

If param is 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 when param is represented in a 32-bit representation. It is of the Number type.

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));

Free Resources