Skip to content

Instantly share code, notes, and snippets.

@dfkaye
Created August 18, 2024 08:15
Show Gist options
  • Save dfkaye/59ab4fcbbbc2ee444d01454db4ce96a6 to your computer and use it in GitHub Desktop.
Save dfkaye/59ab4fcbbbc2ee444d01454db4ce96a6 to your computer and use it in GitHub Desktop.
parse bigint
// 1 July 2024
// parseBigInt
function parseBigInt(b, r) {
var n = String(b).split("n")[0];
return parseInt(n, r);
}
var base10 = ["2n.3", "5.5", "FFnA", "n.3"].map(function (v, i) {
return parseBigInt(v, 8);
});
var base16 = ["9n.3", "15.5", "FFnA", "n.3"].map(function (v, i) {
return parseBigInt(v, 16);
});
var bigInts = [ BigInt(54321), BigInt(121345) ];
[].concat(base10, base16, bigInts).join(", ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment