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

javascript 10进制和64进制的转换

时间:2014-11-09 19:29:39      阅读:856      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   java   sp   

原文:javascript 10进制和64进制的转换

function string10to64(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 string64to10(number_code) {
    var chars = ‘0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ-~‘,
        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++) * chars.indexOf(number_code.charAt(len - i) || 0);
    }
    return origin_number;
}

 

javascript 10进制和64进制的转换

标签:style   blog   http   io   color   ar   os   java   sp   

原文地址:http://www.cnblogs.com/lonelyxmas/p/4085639.html

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