The Math.clz32( ) function in JavaScript returns the number of leading zero bits in the 32-bit binary representation of a number. Clz32 stands for Count Leading Zeros 32. If the passed parameter is not a number, then it will be converted into a number first and then converted to a 32-bit unsigned integer. If the converted 32-bit unsigned integer is 0, then the function returns 32, since all the bits are 0.
Syntax:
Math.clz32(number)
Parameters Used: number: It is the value that is to be tested for CountLeadingZeros.
Return Value: It returns the number of leading zero bits in the 32-bit binary representation of the given number.
Example 1: When a positive number is passed as a parameter.
Javascript
<script type= "text/javascript" > console.log( "Output : " + Math.clz32(5)); </script> |
Output:
Output : 29
Example 2: When a negative number is passed as a parameter.
Javascript
<script type= "text/javascript" > console.log( "Output : " + Math.clz32(-5)); </script> |
Output:
Output : 0
Example 3: When zero is passed as a parameter.
Javascript
<script type= "text/javascript" > document.write( "Output : " + Math.clz32(0)); </script> |
Output:
Output : 32
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Supported Browsers:
- Google Chrome 1 and above
- Internet Explorer 3 and above
- Firefox 1 and above
- Opera 3 and above
- Safari 1 and above