Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | BigInt.asUintN() Method

  • Last Updated : 16 Apr, 2020

The BigInt.asUintN() method is an inbuilt method in JavaScript which is used to wrap a BigInt value to a unsigned integer between 0 and 2width-1.


BigInt.asUintN (width, bigint);

Parameters: This method accept two parameters as mentioned above and described below:

  • width: This parameter holds the amount of bits available for the integer size.
  • bigint: This parameter holds the integer to clamp to fit into the supplied bits.

Return value: This method returns the value of bigint modulo 2width as a unsigned integer.

Below examples illustrate the BigInt.asUintN() method in JavaScript:

Example 1:

let maxlimit = 2n ** (64n - 1n) - 1n;
function GFG(num) {
  (num > maxlimit) ?
    console.log("Number exceed the limit "
           + "of signed 64-bit integer!");
    console.log(BigInt.asUintN(64, num));
GFG(2n ** 16n);
GFG(2n ** 32n);
GFG(2n ** 64n);


"Number exceed the limit of signed 64-bit integer!"

Example 2:

const max = 2n ** (64n - 1n) - 1n;
console.log(BigInt.asUintN(64, max));
console.log(BigInt.asUintN(64, max + 1n));
console.log(BigInt.asUintN(32, max));



Supported Browsers: The browsers supported by BigInt.asUintN() method are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari
  • Edge
My Personal Notes arrow_drop_up
Recommended Articles
Page :