Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from Hex to ASCII in JavaScript?

Tags:

javascript

How to convert from Hex string to ASCII string in JavaScript?

Ex:

32343630 it will be 2460

like image 457
Q8Y Avatar asked Sep 19 '10 12:09

Q8Y


2 Answers

function hex2a(hexx) {     var hex = hexx.toString();//force conversion     var str = '';     for (var i = 0; i < hex.length; i += 2)         str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));     return str; } hex2a('32343630'); // returns '2460' 
like image 196
Delan Azabani Avatar answered Sep 30 '22 23:09

Delan Azabani


Another way to do it (if you use Node.js):

var input  = '32343630'; const output = Buffer.from(input, 'hex'); log(input + " -> " + output);  // Result: 32343630 -> 2460 
like image 23
0x8BADF00D Avatar answered Sep 30 '22 22:09

0x8BADF00D