[英]How to convert hexlified binary data to unicode string
I'm trying to "decode" a Unicode string from a hexlified binary data on node.js. 我正在尝试从node.js上的十六进制二进制数据“解码” Unicode字符串。
const convert = (from, to) => (str) => Buffer.from(str, from).toString(to);
const hexToUtf8 = convert('hex', 'utf8');
const content = hexToUtf8(data.binary)
But when I send the following data: 但是当我发送以下数据时:
Sent from your Twilio trial account - ¿Cómo estás?
从您的Twilio试用帐户-¿Cómoestás发送?
It's getting converted as 它被转换为
Sent from your Twilio trial account - C mo est s?
从您的Twilio试用帐户发送-``Cest''?
The binary data was 53656e742066726f6d20796f7572205477696c696f20747269616c206163636f756e74202d20bf43f36d6f20657374e1733f
二进制数据是
53656e742066726f6d20796f7572205477696c696f20747269616c206163636f756e74202d20bf43f36d6f20657374e1733f
It looks like you bytes were encoded as latin1: 看起来您的字节被编码为latin1:
let data = "53656e742066726f6d20796f7572205477696c696f20747269616c206163636f756e74202d20bf43f36d6f20657374e1733f"
let b = Buffer.from(data, 'hex')
console.log(b.toString('latin1'))
Prints 打印
Sent from your Twilio trial account - ¿Cómo estás?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.