List of utility methods to do Number to Base Convert
toBase(base)"use strict"; Number.prototype.toBase = function (base) { var symbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); var decimal = this; var conversion = ""; if (base > symbols.length || base <= 1) { return false; while (decimal >= 1) { conversion = symbols[(decimal - (base * Math.floor(decimal / base)))] + conversion; decimal = Math.floor(decimal / base); return (base < 11) ? parseInt(conversion) : conversion; | |
toBijectiveBase26( ()Number.prototype.toBijectiveBase26 = (function () { return function toBijectiveBase26() { n = this ret = ""; while(parseInt(n)>0){ --n; ret += String.fromCharCode("A".charCodeAt(0)+(n%26)); n/=26; return ret.split("").reverse().join(""); }; }()); | |
base(b,c)Number.prototype.define("base", function(b, c) { var s = "", n = this if (b > (c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").split("")).length || b < 2) { return "" while (n) { s = c[n % b] + s, n = Math.floor(n / b) return s ... |