整数の配列を使用して JavaScript で BigInt 型を実装しようとしています。今のところ、それぞれに 256 の上限があります。すべての整数演算の実装を終了しましたが、BigInt をその文字列表現に変換する方法がわかりません。もちろん、簡単な方法は次のとおりです。
BigInt.prototype.toString = function(base) {
var s = '', total = 0, i, conv = [
,,
'01',
'012',
'0123',
'01234',
'012345',
'0123456',
'01234567',
'012345678',
'0123456789',
,
,
,
,
,
'0123456789abcdef'
];
base = base || 10;
for(i = this.bytes.length - 1; i >= 0; i--) {
total += this.bytes[i] * Math.pow(BigInt.ByteMax, this.bytes.length - 1 - i);
}
while(total) {
s = conv[base].charAt(total % base) + s;
total = Math.floor(total / base);
}
return s || '0';
};
しかし、BigInts が実際に大きくなると、追加して変換できなくなります。base-x の配列を base-y の配列に変換するにはどうすればよいですか?