diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/bigint/asuintn/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/bigint/asuintn/index.html | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint/asuintn/index.html b/files/zh-cn/web/javascript/reference/global_objects/bigint/asuintn/index.html new file mode 100644 index 0000000000..2c813a51ad --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/bigint/asuintn/index.html @@ -0,0 +1,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> |