From 4b1a9203c547c019fc5398082ae19a3f3d4c3efe Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:15 -0500 Subject: initial commit --- .../reference/global_objects/math/clz32/index.html | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 files/de/web/javascript/reference/global_objects/math/clz32/index.html (limited to 'files/de/web/javascript/reference/global_objects/math/clz32') diff --git a/files/de/web/javascript/reference/global_objects/math/clz32/index.html b/files/de/web/javascript/reference/global_objects/math/clz32/index.html new file mode 100644 index 0000000000..ac7c78c4a7 --- /dev/null +++ b/files/de/web/javascript/reference/global_objects/math/clz32/index.html @@ -0,0 +1,112 @@ +--- +title: Math.clz32() +slug: Web/JavaScript/Reference/Global_Objects/Math/clz32 +tags: + - ECMAScript 2015 + - Java + - Math + - Method + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Math/clz32 +--- +
{{JSRef}}
+ +

Die Math.clz32() Funktion zählt die führenden Nullbits in der 32-Bit binär Repräsentation einer Nummer.

+ +
{{EmbedInteractiveExample("pages/js/math-clz32.html")}}
+ + + +

Syntax

+ +
Math.clz32(x)
+ +

Parameter

+ +
+
x
+
Eine Nummer.
+
+ +

Rückgabewert

+ +

Die Anzahl der führenden Nullbits in der 32-Bit binör Repräsentation der übergebenen Zahl.

+ +

Beschreibung

+ +

"clz32" steht für CountLeadingZeroes32 (AnzahlFührenderNullen32).

+ +

Wenn x keine Nummer ist, wird x in eine Nummer konvertiert. Danach wird diese Nummer in einen 32-Bit vorzeichenlose Ganzzahl (unsigned integer) konvertiert.

+ +

Wenn die konvertierte 32-Bit vorzeichenlose Zahl 0 ist, so wird die Funktion 32 zurück geben, weil alle Bits 0 sind.

+ +

Diese Funktion ist nützlich für Systeme, die in zu JavaScript kompilieren (z. B. Emscripten).

+ +

Beispiele

+ +

Einsatz von Math.clz32()

+ +
Math.clz32(1);                // 31
+Math.clz32(1000);             // 22
+Math.clz32();                 // 32
+
+[NaN, Infinity, -Infinity, 0, -0, null, undefined, 'foo', {}, []].filter(
+function(n) {
+  return Math.clz32(n) !== 32
+});                           // []
+
+Math.clz32(true);             // 31
+Math.clz32(3.5);              // 30
+
+ +

Polyfill

+ +

Der folgende Polyfill ist der effizienteste.

+ +
if (!Math.clz32) {
+  Math.clz32 = function(x) {
+    // Let n be ToUint32(x).
+    // Let p be the number of leading zero bits in 
+    // the 32-bit binary representation of n.
+    // Return p.    
+    if (x == null || x === 0) {
+      return 32;
+    }
+    return 31 - Math.floor(Math.log(x >>> 0) * Math.LOG2E);
+  };
+}
+ +

Spezifikationen

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES2015', '#sec-math.clz32', 'Math.clz32')}}{{Spec2('ES2015')}}Initiale Definition.
{{SpecName('ESDraft', '#sec-math.clz32', 'Math.clz32')}}{{Spec2('ESDraft')}} 
+ +

Browserkompatibilität

+ + + +

{{Compat("javascript.builtins.Math.clz32")}}

+ +

Siehe auch

+ + -- cgit v1.2.3-54-g00ecf