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

  1. When a positive number is passed as a parameter.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
            document.write("Output : " + Math.clz32(5));          
         </script>

    chevron_right

    
    

    Output:

    Output : 29
  2. When a negative number is passed as a parameter.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
            document.write("Output : " + Math.clz32(-5));          
         </script>

    chevron_right

    
    

    Output:

    Output : 0
  3. When zero is passed as a parameter.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
            document.write("Output : " + Math.clz32(0));          
         </script>

    chevron_right

    
    

    Output:

    Output : 32


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.