JavaScript Math.clz32()
Example
let a = Math.clz32(0);
let b = Math.clz32(1);
let c = Math.clz32(2);
let d = Math.clz32(4);
Try it Yourself »
Definition and Usage
The Math.clz32()
method (short for CountLeadingZeroes32),
returns the number of leading zeros in a 32-bit binary representation of a number.
Browser Support
Math.clz32()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Math.clz32()
is not supported in Internet Explorer 11 (or earlier).
Syntax
Math.clz32(x)
Parameters
Parameter | Description |
---|---|
x | Required. A number |
Return Value
The number of leading zeros bits in the 32-bit binary representation of a number. If the number is 0, then this method returns 32 (as all bits are 0). |