如何在JavaScript中将表示为字符串的十六进制代码转换为字节,以及反向转换?
var conv = require('binstring');
var hexstring ='80';
var bytestring = conv(hexstring, {in:'hex', out:'utf8'});
var backtohexstring = conv(bytestring, {in:'utf8', out:'hex'}); // != '80'???
backtohexstring函数将传入的数据字符串解码为正确的十六进制(我使用utf8而不是byte,因为它在控制台打印时看起来像传入的字符串),所以我感到困惑...
我还发现了这两个原生的JavaScript函数,解码器可以处理我的传入流,但我仍然无法获得十六进制编码...
function encode_utf8( s ) {
return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s ) {
return decodeURIComponent( escape( s ) );
}
5648
这样的字节串? - adeneo