JavaScript | Math.clz32( )
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 which 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.
Examples:
Input : Math.clz32(5) Output : 29 Input : Math.clz32(-5) Output : 0 Input : Math.clz32(0)); Output : 32
- When a positive number is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.clz32(5));
</
script
>
chevron_rightfilter_noneOutput:
Output : 29
- When a negative number is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.clz32(-5));
</
script
>
chevron_rightfilter_noneOutput:
Output : 0
- When zero is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.clz32(0));
</
script
>
chevron_rightfilter_noneOutput:
Output : 32
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.