2009-02-18 Convert ESN from DEC to HEX 3268 0 摘要:Convert ESN from DEC to HEX <HTML> <HEAD> <TITLE>CDMA ESN HEX<->DEC Converter</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- Copyright (C) 2000 Valerio Capello (valcap@thepentagon.com) --> function convdh() { var aS=document.console.frNum.value; aS=aS.toUpperCase(); b=10; ba=16; var r1=unilenS(baseconv(leftS(aS,3),b,ba),2); var r2=unilenS(baseconv(midS(aS,4),b,ba),6); var rS=""+r1+r2; document.console.toNum.value=rS; } function convhd() { var aS=document.console.toNum.value; aS=aS.toUpperCase(); b=16; ba=10; var r1=unilenS(baseconv(leftS(aS,2),b,ba),3); var r2=unilenS(baseconv(midS(aS,3),b,ba),8); var rS=""+r1+r2; document.console.frNum.value=rS; } function baseconv(aS,b,ba) { var rS=aS; for (var i=1;i==1;i++) { // if (b==ba) {break;} if (b==10) {rS=DecObas(aS,ba); break;} if (ba==10) {rS=ObasDec(aS,b); break;} var xS=ObasDec(aS,b); rS=DecObas(xS,ba); aS=xS; } if (leftS(rS,1)=="0" && rS!="0" && ba>1) {rS=midS(rS,2);} return rS; } function DecObas(co,ba) { var bS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var rS=""; co*=1; if (ba>1) { var n=new makeArray(40); var j=1; for (var i=0;i>=-1;i--) { var qu=Math.floor(co/ba); var re=co-qu*ba; n[j]=re; j++; co=qu; if (co<ba) {i=-2;} i++; } n[j]=co; for (var h=j;h>=1;h--) {rS+=midS(bS,n[h]+1,1);} } else { for (var h=1;h<=co;h++) {rS+=leftS(bS,1);} } return rS; } function ObasDec(aS,b) { var bS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var tl=0; if (b>1) { var c=0; var dS=""; var v=0; for (var x=aS.length;x>=1;x--) { c++; dS=midS(aS,c,1); t=asc(dS); if (dS>midS(bS,b,1)) {alert("'"+dS+"' doesn't exists in base "+b); break;} if (t<48||t>70) {break;} if (t>57&&t<65) {break;} if (t>64) {v=t-55;} if (t<58) {v=dS*1;} if (v>b) {break;} tl+=v*Math.pow(b,(x-1)); } } else { tl=aS.length; } return tl; } function unilenS(aS,ul,fc) { var rS=""+aS; ul*=1.0; if (fc=="" || fc==null) {fc="0";} var rL=rS.length; if (rL<ul) { for (var i=1;i<=ul-rL;i++) {rS=""+fc+rS;} } return rS; } function makeArray(n) { this.length=n; for (var i=1;i<=n;i++) {this[i]=0;} return this; } function clrI1() { document.console.frNum.value=""; } function clrI2() { document.console.toNum.value=""; } // BASIC Commands // String function asc(aS) { aS+=""; var r=0; if (aS!="") { var ascii=" !"+unescape("%22")+"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "; var r=ascii.indexOf(aS.substring(0,1))+32; if (r==31) {r=-1;} } return r; } function leftS(aS,n) { aS+=""; var rS=""; if (n>=1) { rS=aS.substring(0,n); } return rS; } function midS(aS,n,n2) { aS+=""; var rS=""; if (n2==null || n2=="") {n2=aS.length;} n*=1; n2*=1; if (n<0) {n++;} rS=aS.substring(n-1,n-1+n2); return rS; } </SCRIPT> </HEAD> <BODY> <P><BR> <CENTER> <TT> <FONT SIZE=+3><B>CDMA ESN HEX-DEC Converter</B></FONT><BR> <FONT SIZE=-1>v1.01 r15Sep2000 </FONT><BR> <I>by <A HREF="http://www.ElfQrin.com" TARGET=NEW>Elf Qrin</A></I></B> <P><BR><BR> <FORM NAME="console"> <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2><TR><TD> <FONT FACE="Courier New, Courier"><TT> <SUP><FONT SIZE=+1><B>Dec</B></FONT></SUP> <INPUT TYPE=BUTTON VALUE="x" onClick="clrI1();"><INPUT TYPE=TEXT NAME=frNum SIZE=11 MAXLENGTH=11> <INPUT TYPE=BUTTON VALUE="->" onClick="convdh();"> <INPUT TYPE=BUTTON VALUE="<-" onClick="convhd();"> <INPUT TYPE=TEXT NAME=toNum SIZE=8 MAXLENGTH=8><INPUT TYPE=BUTTON VALUE="x" onClick="clrI2();"> <SUP><FONT SIZE=+1><B>Hex</B></FONT></SUP> </TT></FONT> </TD></TR></TABLE> </FORM> </CENTER> <P ALIGN=RIGHT> </BODY> </HTML>http://hi.baidu.com/tombkeeper/blog/item/53ef11081c8050d463d9866a.html 回首頁