|
发表于 2007-1-2 11:09:15
|
显示全部楼层
这个是javascript的吧aaaa转换成1212121212的程序 保存为网页运行就可以了- <SCRIPT LANGUAGE="JavaScript">
- <!--
- function encMe() {
- var charout = 0;
- var code = 0;
- for(i=0;i<document.encme.inps.value.length-1;i++) {
- code = document.encme.inps.value.charCodeAt(0);
- charout+=code*Math.pow(2,8*(document.encme.inps.value.length-i-1));
- }
- charout+=document.encme.inps.value.charCodeAt(encme.inps.value.length-1);
- document.encme.outs.value=charout;
- }
- //-->
- </SCRIPT>
- <title>String To Int 转换程序</title>
- </head>
- <body>
- <form name=encme>
- <input type=text name=inps size=40>
- <input type=button onclick=encMe() value="转换">
- <br /><input type=text name=outs size=47>
- </form>
- </body>
复制代码
这个是jass的互相转换的例子 呵呵不是我写的- function S2Id takes string source returns integer
- local string num = "0123456789"
- local string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- local string abc = "abcdefghijklmnopqrstuvwxyz"
- local integer Id = 0
- local integer n1 = 1
- local integer n2 = 1
- loop
- exitwhen n1 > StringLength(source)
- loop
- exitwhen n2 > 10
- if SubString(source,n1-1,n1) == SubString(num,n2-1,n2) then
- set Id = Id + R2I(('0'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
- set n2 = n2 + 1
- else
- set n2 = n2 + 1
- endif
- endloop
- set n2 = 1
- loop
- exitwhen n2 > 26
- if SubString(source,n1-1,n1) == SubString(ABC,n2-1,n2) then
- set Id = Id + R2I(I2R('A'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
- set n2 = n2 + 1
- else
- set n2 = n2 + 1
- endif
- endloop
- set n2 = 1
- loop
- exitwhen n2 > 26
- if SubString(source,n1-1,n1) == SubString(abc,n2-1,n2) then
- set Id = Id + R2I(('a'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
- set n2 = n2 + 1
- else
- set n2 = n2 + 1
- endif
- endloop
- set n2 = 1
- set n1 = n1 + 1
- endloop
- return Id
- //return
- endfunction
- function Id2S takes integer int returns string
- local string num = "0123456789"
- local string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- local string abc = "abcdefghijklmnopqrstuvwxyz"
- local string target = ""
- local integer n = 0
- local integer dis = 0
- loop
- exitwhen int == 0
- set n = ModuloInteger(int,256)
- if n>='0' and n<='9' then
- set dis = n-'0'
- set target = SubString(num,dis,dis+1) + target
- endif
- if n>='A' and n<='Z' then
- set dis = n-'A'
- set target = SubString(ABC,dis,dis+1) + target
- endif
- if n>='a' and n<='z' then
- set dis = n-'a'
- set target = SubString(abc,dis,dis+1) + target
- endif
- set int = int/256
- endloop
- return target
- //return
- endfunction
复制代码 |
|