首页 > 编程语言 > 详细

javascript 10进制和62进制的转换

时间:2014-07-30 11:27:03      阅读:442      评论:0      收藏:0      [点我收藏+]
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进制的转换

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!