peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

radix larger than 36 (enhancement request) #107

Closed dpalay closed 7 years ago

dpalay commented 7 years ago

I haven't yet found another library that lets me convert very large numbers into bases higher than 36. It would be very helpful for compressing large numbers down.

Yaffle commented 7 years ago

@dpalay how should it work?

peterolson commented 7 years ago

Hi,

BigInteger.js already supports conversion to and from bases higher than 36, as well as negative bases. Can you clarify exactly what you're requesting?

dpalay commented 7 years ago

Hi Peter, Absolutely! Sorry, I blanked on the fact that it CAN already do this, but what I had meant was to be able to define an alphabet, instead of having the syntax.
Currently, the alphabet is 0-9a-z and then above that is . I'd like to be able to set a different alphabet, such as 0-9a-zA-Z, or even including other symbols. For instance, 35 in all of the bases greater than 35 is a z. 36 currently is <36>, but I'd like to be able to define (or have the pre-set) of 36 being A, 37 being B, etc.

benjaminBrownlee commented 7 years ago

This sounds like something that would be easier to (and specific enough to) incorporate personally into your code. Take the example from the README.md for example:

bigInt(567890).toString(100) => "<56><78><90>"

A very simple string parser and switch statement in an iterative loop could easily digest this string and spit out what you would like each numbers -- <56>, <78>, and <90> -- to stand for instead. Defining a library would take nearly as much time, as you would still have to define each number case and the letter/number you want to represent it as.

peterolson commented 7 years ago

As benjaminBrownlee said, I think this is a specific enough functionality that it would make more sense to handle in user code rather than baking it into the library.