aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/math/clz32/index.html
blob: ac7c78c4a78971141106457fa9ae15af4fddf1a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
---
<div>{{JSRef}}</div>

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

<div>{{EmbedInteractiveExample("pages/js/math-clz32.html")}}</div>



<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><code>Math.clz32(<var>x</var>)</code></pre>

<h3 id="Parameter">Parameter</h3>

<dl>
 <dt><code>x</code></dt>
 <dd>Eine Nummer.</dd>
</dl>

<h3 id="Rückgabewert">Rückgabewert</h3>

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

<h2 id="Beschreibung">Beschreibung</h2>

<p>"<code>clz32</code>" steht für <code>CountLeadingZeroes32 (<em>AnzahlFührenderNullen32</em>)</code>.</p>

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

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

<p>Diese Funktion ist nützlich für Systeme, die in zu JavaScript kompilieren (z. B. <a href="/en-US/docs/Emscripten">Emscripten</a>).</p>

<h2 id="Beispiele">Beispiele</h2>

<h3 id="Einsatz_von_Math.clz32()">Einsatz von <code>Math.clz32()</code></h3>

<pre class="brush: js">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
</pre>

<h2 id="Polyfill">Polyfill</h2>

<p>Der folgende Polyfill ist der effizienteste.</p>

<pre class="brush: js line-numbers  language-js"><code class="language-js"><span class="keyword token">if</span> <span class="punctuation token">(</span><span class="operator token">!</span>Math<span class="punctuation token">.</span>clz32<span class="punctuation token">)</span> <span class="punctuation token">{</span>
  Math<span class="punctuation token">.</span>clz32 <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span>
    <span class="comment token">// Let n be ToUint32(x).</span>
    <span class="comment token">// Let p be the number of leading zero bits in </span>
    <span class="comment token">// the 32-bit binary representation of n.</span>
    <span class="comment token">// Return p.    </span>
    <span class="keyword token">if</span> <span class="punctuation token">(</span>x <span class="operator token">==</span> <span class="keyword token">null</span> <span class="operator token">||</span> x <span class="operator token">===</span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
      <span class="keyword token">return</span> <span class="number token">32</span><span class="punctuation token">;</span>
    <span class="punctuation token">}</span>
    <span class="keyword token">return</span> <span class="number token">31</span> <span class="operator token">-</span> Math<span class="punctuation token">.</span><span class="function token">floor</span><span class="punctuation token">(</span>Math<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>x <span class="operator token">&gt;</span><span class="operator token">&gt;</span><span class="operator token">&gt;</span> <span class="number token">0</span><span class="punctuation token">)</span> <span class="operator token">*</span> Math<span class="punctuation token">.</span>LOG2E<span class="punctuation token">)</span><span class="punctuation token">;</span>
  <span class="punctuation token">}</span><span class="punctuation token">;</span>
<span class="punctuation token">}</span></code></pre>

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES2015', '#sec-math.clz32', 'Math.clz32')}}</td>
   <td>{{Spec2('ES2015')}}</td>
   <td>Initiale Definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-math.clz32', 'Math.clz32')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browserkompatibilität">Browserkompatibilität</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("javascript.builtins.Math.clz32")}}</p>

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li>{{jsxref("Math")}}</li>
 <li>{{jsxref("Math.imul")}}</li>
</ul>