Javascript 字符 (ASCII) 到十六进制 [英] Javascript character (ASCII) to Hex
本文介绍了Javascript 字符 (ASCII) 到十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我需要一些简单的方法将字符转换为 ASCII,然后将其转换为十六进制代码.
Hey all i am in need of something simple to convert character(s) into ASCII and then make that into a Hex code.
例如,A"字符将是:
0xF100 + ascii_code = Hex
结果是:
0xF100 + 65 = 0xF141
65 将是上面的字符A".我一直在寻找一些 javascript 来获取我的角色并从中制作一个十六进制......但我还没有真正找到任何可以做到这一点的东西......
65 would be the character "A" above. I've been looking for some javascript that would take my character and make a Hex from it... But i haven't really found anything that would do this....
任何帮助都会很棒!
推荐答案
Number 的 toString
接受一个基数参数,您可以使用它来将 ASCII 代码转换为十六进制,如下所示:
Number's toString
accepts a radix parameter, with which you can convert the ASCII code to hexadecimal like this:
var data = "A";
console.log("0xF1" + data.charCodeAt(0).toString(16));
16 表示基数为 16,即十六进制.
16 means base 16, which is hexadecimal.
这篇关于Javascript 字符 (ASCII) 到十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文