使用节点js将十六进制转换为ASCII

问题描述 投票:-2回答:1

我想将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!

javascript node.js hex ascii non-printing-characters
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.