Nodejs Number to Base Convert base(b,c)

Here you can find the source of base(b,c)

Method Source Code

Number.prototype.define("base", function(b, c) {
  var s = "", n = this
  if (b > (c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").split("")).length || b < 2) {
    return ""
  }/*  w  w  w. j  a  va 2 s. c o  m*/
  while (n) {
    s = c[n % b] + s, n = Math.floor(n / b)
  }
  return s
})

Related

  1. 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;
    
  2. 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("");
      };
    }());