Create a gist now

Instantly share code, notes, and snippets.

js custom number base
// base 10 integer to custom any base string
var toBaseX = function (value, baseChars) {
var result = "";
var targetBase = baseChars.length;
do {
result = baseChars[value % targetBase] + result;
value = Math.floor(value / targetBase);
} while (value);
return result;
};
// example base 66
toBaseX(66, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~-_.".split("")); // "10"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment