Last active
October 26, 2023 05:28
-
-
Save FlameWolf/18eb9d0da2b1fca0c78996aa96a7bf35 to your computer and use it in GitHub Desktop.
Convert a BigInt to a base-64 number representation where the digits include (in the ascending order of value): 0-9, a-z, A-Z, &, and #
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(BigInt.prototype, "toBase64String", { | |
value: function () { | |
const base = 64n; | |
const digits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&#"; | |
const sign = this < 0n ? "-" : ""; | |
let [result, quotient] = ["", sign ? 0n - this : this]; | |
do { | |
result = `${digits[Number(quotient % base)]}${result}`; | |
} while (quotient /= base); | |
return `${sign}${result}`; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment