Syntax error What is the use of Math.clz32() method in JavaScript?

What is the use of Math.clz32() method in JavaScript?



Math.clz32()

The Math.clz32() function returns the number of leading zero bits in the 32-bit binary representation of a number. In a binary representation, there are 32 numbers consisting of only 1's and 0's. This method scrutinizes through each and every element and returns the number of 0's.

syntax

Math.clz32(number);

Example-1

In the following example, numbers 1 and 0 were passed into the Math.Clz32() function and the number of trailing zeroes were displayed in the output.

Live Demo

<html>
<body>
<script>
   document.write(Math.clz32(1));
   document.write("</br>");
   document.write(Math.clz32(0));
</script>
</body>
</html>

Output

31
32


Example-2

In the following example, numbers 21 and 20 were passed into the Math.Clz32() function and the number of trailing zeroes(27, 27) were displayed in the output.

Live Demo

<html>
<body>
<script>
   document.write(Math.clz32(21));
   document.write("</br>")
   document.write(Math.clz32(20))
</script>
</body>
</html>

Output

27
27
Updated on: 2019-07-31T13:18:13+05:30

164 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements