--- title: BigInt.asUintN() slug: Web/JavaScript/Reference/Global_Objects/BigInt/asUintN tags: - BigInt - JavaScript - Method - Reference - asUintN - メソッド translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/asUintN ---
{{JSRef}}

BigInt.asUintN 静的メソッドは、 BigInt 値を 0 から 2width-1 までの間の符号なし整数に丸めるために使われます。

{{EmbedInteractiveExample("pages/js/bigint-asuintn.html", "taller")}}

構文

BigInt.asUintN(width, bigint);

引数

width
整数の大きさのために利用できるビットの数。
bigint
指定されたビットに収めるよう丸める整数値。

返値

bigint を 2width で割った剰余の値の符号なし整数です。

64ビットの範囲に収める

BigInt.asUintN() メソッドは、64ビットの数値の範囲に収めるのに便利です。

const max = 2n ** 64n - 1n;

BigInt.asUintN(64, max);
// ↪ 18446744073709551615n

BigInt.asUintN(64, max + 1n);
// ↪ 0n
// オーバーフローするのでゼロになる

仕様書

仕様書
{{SpecName('ESDraft', '#sec-bigint.asuintn', 'BigInt.asUintN()')}}

ブラウザーの互換性

{{Compat("javascript.builtins.BigInt.asUintN")}}

関連情報