我想将hex
转换为ASCII
,但出现不可打印字符的问题,这是我使用的代码:
function hex_to_ascii(str1) {
var hex = str1.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2) {
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
}
return str;
}
console.log(hex_to_ascii("646566010203"));
实际输出:def╔╗╚
预期输出:def SOH STX ETX
例如,我想获得不可打印的字符:当我输入“ 01”时,我想得到SOH!