Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年9月.
BigInt.asIntN は静的メソッドで、長整数を符号付き整数値に丸め、その値を返します。
返される長整数に使用可能なビット数。0 から 253 - 1 までの整数である必要があります(両端を含む)。
bigint指定されたビット数に丸める長整数値です。
bigint を 2 ** bits で割った剰余の値の符号付き整数です。
bits が負または 253 - 1 より大きい場合に発生します。
BigInt.asIntN メソッドは、長整数を指定されたビット数で切り捨て、結果を符号付き整数として解釈します。例えば、BigInt.asIntN(3, 25n) の場合、値 25n は 1n に切り捨てられます。
25n = 00011001 (base 2) ^=== 最後の 3 ビットのみを使用 ===> 001 (base 2) = 1n残りの数値の最上位ビットが 1 の場合、結果は負の数となる。例えば、BigInt.asIntN(4, 25n) は -7n を返す。これは 1001 が 2 の補数表現における -7 の符号化値であるためです。
25n = 00011001 (base 2) ^==== 最後の 4 ビットのみを使用 ===> 1001 (base 2) = -7nメモ: BigInt の値は常に 2 進数の 2 の補数形式でエンコードされます。
類似の言語 API(例:Number.prototype.toExponential())とは異なり、asIntN は BigInt の静的プロパティであるため、BigInt 値のメソッドとしてではなく、常に BigInt.asIntN() として使用します。asIntN() を「標準ライブラリ関数」として公開することで、asm.js との相互運用性が実現されます。
BigInt.asIntN() メソッドは、64 ビットの数値の範囲に収めるのに便利です。
| ECMAScript® 2027 Language Specification # sec-bigint.asintn |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年11月30日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.