JavaScript Math clz32 ()

Die JavaScript-Funktion Math.clz32 () gibt die Anzahl der führenden Nullbits in der 32-Bit-Binärdarstellung einer Zahl zurück.

Hier clz32ist die Abkürzung für CountLeadingZeroes32 .

Die Syntax der Math.clz32()Funktion lautet:

 Math.clz32(x)

clz32()Da es sich um eine statische Methode handelt, wird sie mit dem MathKlassennamen aufgerufen .

Math.clz32 () Parameter

Die Math.clz32()Funktion umfasst:

  • x - Eine Zahl

Rückgabewert von Math.clz32 ()

  • Gibt die Anzahl der führenden Nullbits in der 32-Bit-Binärdarstellung der Zahl zurück.

Beispiel: Verwenden von Math.clz32 ()

 // 00000000000000000000000000000001 var value = Math.clz32(1); console.log(value); // 31 // 00000000000000000000001111101000 var value = Math.clz32(1000); console.log(value); // 22 // 00000000000000000000000000000100 var value = Math.clz32(4); console.log(value); // 29 var value = Math.clz32(true); console.log(value); // 31 var value = Math.clz32(0); console.log(value); // 32

Ausgabe

 31 22 29 31 32

Interessante Beiträge...