blob: 2c813a51ad9cff7e0de63134984bfda1feab6989 (
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
|
---
title: BigInt.asUintN()
slug: Web/JavaScript/Reference/Global_Objects/BigInt/asUintN
translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/asUintN
---
<div>{{JSRef}}</div>
<p><strong><code>BigInt.asUintN</code></strong> 静态方法将 <code>BigInt</code> 转换为一个 0 和 2<sup>width</sup>-1 之间的无符号整数。</p>
<div>{{EmbedInteractiveExample("pages/js/bigint-asuintn.html")}}</div>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">BigInt.asUintN(<var>width</var>, <var>bigint</var>);</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>width</code></dt>
<dd>可存储整数的位数。</dd>
<dt><code>bigint</code></dt>
<dd> 要存储在指定位数上的整数。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<p><code>bigint</code> 模(modulo) 2<sup><code>width</code></sup> 作为无符号整数的值。</p>
<h2 id="例子">例子</h2>
<h3 id="保持在64位范围内">保持在64位范围内</h3>
<p><code>BigInt.asUintN()</code> 方法对于保持在64位(64-bit)算数范围内非常有用。</p>
<pre class="brush: js">const max = 2n ** 64n - 1n;
BigInt.asUintN(64, max);
// ↪ 18446744073709551615n
BigInt.asUintN(64, max + 1n);
// ↪ 0n
// zero because of overflow</pre>
<h2 id="标准">标准</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-bigint.asuintn', 'BigInt.asUintN()')}}</td>
<td>{{Spec2('ESDraft')}}</td>
</tr>
</tbody>
</table>
<h2 id="浏览器支持">浏览器支持</h2>
<p>{{Compat("javascript.builtins.BigInt.asUintN")}}</p>
<h2 id="请参阅">请参阅</h2>
<ul>
<li>{{JSxRef("BigInt")}}</li>
<li>{{JSxRef("BigInt.asIntN()")}}</li>
</ul>
|