blob: 98395a3c5c062b71f009db1acbcfafca0c3777f6 (
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>The <strong><code>BigInt.asUintN</code></strong> static method is used to wrap a BigInt value to an unsigned integer between 0 and 2<sup>width</sup>-1.</p>
<div>{{EmbedInteractiveExample("pages/js/bigint-asuintn.html", "taller")}}</div>
<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">BigInt.asUintN(<var>width</var>, <var>bigint</var>);</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
<dt><code><var>width</var></code></dt>
<dd>The amount of bits available for the integer size.</dd>
<dt><code><var>bigint</var></code></dt>
<dd>The integer to clamp to fit into the supplied bits.</dd>
</dl>
<h3 id="Returns">Returns</h3>
<p>The value of <code><var>bigint</var></code> modulo 2<sup><code><var>width</var></code></sup> as an unsigned integer.</p>
<h2 id="Examples">Examples</h2>
<h3 id="Staying_in_64-bit_ranges">Staying in 64-bit ranges</h3>
<p>The <code>BigInt.asUintN()</code> method can be useful to stay in the range of 64-bit arithmetic.</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="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-bigint.asuintn', 'BigInt.asUintN()')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("javascript.builtins.BigInt.asUintN")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{JSxRef("BigInt")}}</li>
<li>{{JSxRef("BigInt.asIntN()")}}</li>
</ul>
|