数字转字符
字符转数字
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<p> <style> .btn { font-family: "tahoma", "宋体"; font-size:12pt; color: #003399; border: 1px #003399 solid; color:#006699; border-bottom: #93bee2 1px solid; border-left: #93bee2 1px solid; border-right: #93bee2 1px solid; border-top: #93bee2 1px solid; background-color: #e8f4ff; cursor: hand; font-style: normal ; width:auto; height:40px; float:left; } .txt { font-family: "tahoma", "宋体"; font-size:16pt; color: #003399; border: 1px #003399 solid; color:#006699; border-bottom: #93bee2 1px solid; border-left: #93bee2 1px solid; border-right: #93bee2 1px solid; border-top: #93bee2 1px solid; text-align: center; cursor: hand; font-style: normal ; width:auto; height:36px; float:left; } </style> <input id="1" class="txt" type="text" /> <button class="btn" οnclick="i2a()" type="button">数字转字符</button> <input id="2" class="txt" type="text" /> <br /> <br /> <br /> <input id="3" class="txt" type="text" /> <button class="btn" οnclick="a2i()" type="button">字符转数字</button> <input id="4" class="txt" type="text" /> <script> function i2a() { //1919707494 //726c6966 //0x72 0x6c 0x69 ox66 //r l i f var txt1 = document.getElementById("1") var txt2 = document.getElementById("2") txt2.value =null var dif = new Array(0) var x = (parseInt(txt1.value)).toString(16) for(var i=0;i<x.length;i+=2) { dif.push(parseInt(x.slice(i,i+2),16)) } for (var i=0;i<dif.length;i++) { // txt2.value += String.fromCharCode(dif[i]); } //console.log(dif) } function a2i() { //r l i f //0x72 0x6c 0x69 ox66 //726c6966 //1919707494 var txt3 = document.getElementById("3") var txt4 = document.getElementById("4") txt4.value=null var dif = new Array(0) var x = txt3.value var y ="" for(var i=0;i<x.length;i++) { // dif.push((x[i].charCodeAt()).toString(16)) } for(var i=0;i<dif.length;i++) { // y += dif[i] } txt4.value = parseInt(y,16) } </script> <br /><br /><br /> </p>