Utility for converting numbers to/from different bases/alphabets.
Utility for converting numbers to/from different bases/alphabets. Common bases have convenience aliases (see below), but arbitrary/custom alphabets can be used.
On the server side w/ Node.js:
npm install bases
Or in the browser (adds a global
Bases variable for now):
var bases = ;// or window.Bases in the browserbases; // => 'c8'bases; // => 'q0T'bases; // => 'Abba'bases; // => 200bases; // => 99999bases; // => 300
Going from numbers to strings:
toAlphabet(num, alphabet): returns a string representation of the given
number for the given alphabet, where the alphabet is an arbitrary string of
characters. (See known alphabets below for examples.)
toBase(num, base): convenience helper for known bases (see below).
toBaseX(num): convenience helpers for known bases (see below), e.g.
Going from strings to numbers:
fromAlphabet(str, alphabet): returns an integer representation of the given
string for the given alphabet.
fromBase(num, base): convenience helper for known bases.
fromBaseX(str): convenience helpers for known bases.
|Base-32 (from Douglas Crockford)||
|Base-58 (from Flickr)||
|Base-64 (as standardized)||
Base-64 warning: besides there being several different standards, padding isn't currently added and line lengths aren't tracked. Not recommended for use with APIs that expect formal base-64 strings!