码迷,mamicode.com
首页 > 编程语言 > 详细

javascript 10进制和62进制的转换

时间:2014-07-30 11:27:03      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   io   cti   ar   div   

function string10to62(number) {
    var chars = ‘0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ‘.split(‘‘),
        radix = chars.length,
        qutient = +number,
        arr = [];
    do {
        mod = qutient % radix;
        qutient = (qutient - mod) / radix;
        arr.unshift(chars[mod]);
    } while (qutient);
    return arr.join(‘‘);
}

function string62to10(number_code) {
    var chars = ‘0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ‘.split(‘‘),
        radix = chars.length,
        number_code = String(number_code),
        len = number_code.length,
        i = 0,
        origin_number = 0;
    while (i < len) {
        origin_number += Math.pow(radix, i++) * (+number_code.charAt(len - i) || 0);
    }
    return origin_number;
}

 

javascript 10进制和62进制的转换,布布扣,bubuko.com

javascript 10进制和62进制的转换

标签:style   blog   color   java   io   cti   ar   div   

原文地址:http://www.cnblogs.com/feng524822/p/3877227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!