1

I'm playing around with a minifier where I have a very large base of symbols. I'm looking for a function / library that allows me to do something like:

const a = '123456789876543212345678987654321' // Some huge number
const b = convertBase(a, 10, 16) // (Number, Base: From, Base: To)
// [6,1,6,3,14,6,7,1,2,14,11,11,10,10,4,14,3,13,6,2,11,4,1,15,4,11,1]

In practice, I'd like to convert something like a 255 character hex value to something like, base-1024. Converting from hex to decimal with an arbitrary level of precision is relatively straight forward, but looking around on stackoverflow / npm / github, I'm not seeing a simple example that avoids the use of custom alphabets when working with very large numbers / very large bases.

Is there a better name for this than an "arbitrary precision base conversion represented by an array of decimals"? Where might I find a decent implementation of this function in modern javascript / ECMAScript?

  • Possible duplicate of [How do you convert numbers between different bases in JavaScript?](https://stackoverflow.com/questions/1337419/how-do-you-convert-numbers-between-different-bases-in-javascript) – Tyler Oct 01 '18 at 21:48
  • 1
    @Tyler this is about arbitrary precision – Marouane Fazouane Oct 01 '18 at 21:49
  • @Tyler The accepted answer there `parseInt(string, radix)` gets me as far as a small number converted up to base 36, where I'm ultimately looking for something that can convert very large numbers into very large bases with the result represented by a decimal-form array of the arbitrary sized base symbol offset –  Oct 01 '18 at 21:49
  • @arby Fair enough, thought it would be worth pointing out as it seemed to be a very similar question. – Tyler Oct 01 '18 at 21:53
  • 1
    I found this with a few minutes of searching, it might be what you're after: https://github.com/peterolson/BigInteger.js – thirtydot Oct 02 '18 at 00:59
  • @thirtydot Hey, I think that does the trick! –  Oct 02 '18 at 01:58

0 Answers0