进制转换-2进制~62进制与10进制的转换

//var str="AZ"; 
//for(var i=0;i62 ? 62 : d; 
  var s, e = ""; 
  while (N>0) { 
    s = N%d; 
    if (s>35) { 
      //36至62的数用a-z字符表示(s-36+97) 
      s = String.fromCharCode(s+61); 
    } else if (s>9) { 
      //10至35的数用A-Z字符表示(s-10+65) 
      s = String.fromCharCode(s+55); 
    } 
    e = s+e; 
    N = Math.floor(N/d); 
  } 
  e = e != "" ? e : "0"; 
  return e; 

//将d进制数转换为10进制 
function jh_Dto10(str, d) { 
  d = Math.floor(Number(d)); 
  d = d62 ? 62 : d; 
  var code = 0, num = 0; 
  for (var i = 0; i96) { 
      code -= 61; 
    } else if (code>64) { 
      code -= 55; 
    } else { 
      code -= 48; 
    } 
    num += code*Math.pow(d, str.length-1-i); 
  } 
  return num; 

//测试: 
in_D = 62; 
num1 = "15000"; 
num2 = jh_10toD(num1, in_D); 
bt1.onRelease = function() { 
  num2 = jh_10toD(num1, in_D); 
}; 
bt2.onRelease = function() { 
  num1 = jh_Dto10(num2, in_D); 
}; 
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/310.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值