--- title: BigInt.asIntN() slug: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN tags: - BigInt - JavaScript - Méthode - Reference translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN original_slug: Web/JavaScript/Reference/Objets_globaux/BigInt/asIntN ---
{{JSRef}}
La méthode statique BigInt.asIntN() permet d'écréter un nombre BigInt pour obtenir un entier signé entre 2^(largeur-1) et 2^(largeur-1)-1.
var resultat = BigInt.asIntN(largeur, bigint);
largeurbigintLa valeur de bigint modulo 2^largeur comme entier signé.
La méthode BigInt.asIntN() peut être utile pour rester dans une arithmétique sur 64 bits :
const max = 2n ** (64n - 1n) - 1n; BigInt.asIntN(64, max); // ↪ 9223372036854775807n BigInt.asIntN(64, max + 1n); // ↪ -9223372036854775807n // négatif car dépassement sur le nombre de bits
| Spécification | État |
|---|---|
| BigInt proposal | Proposition de niveau 3. |
{{Compat("javascript.builtins.BigInt.asIntN")}}