Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hey all i am in need of something simple to convert character(s) into ASCII and then make that into a Hex code.

So as an example the "A" character would be:

0xF100 + ascii_code = Hex

and that would turn out to be:

0xF100 + 65 = 0xF141

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....

Any help would be great!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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 means base 16, which is hexadecimal.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...