首页 > 解决方案 > Javascript:十六进制到字符串,无需转换为 ascii、int 或 xyz

问题描述

我有一个字节数组

sensor_id = [bytes[36],bytes[35],bytes[34],bytes[33]]

它包含以下十六进制

0x69, 0x72, 0x33, 0x88

我需要将 69 72 33 88 合并到没有对话 =>“69723388”的字符串值。

感谢您的帮助

标签: javascriptdecodenode-redpayloadlorawan

解决方案


您可以使用 将十六进制值转换为字符串toString(16)。有关更多信息,请阅读MDN 文档

const arr = [0x69, 0x72, 0x33, 0x88];
const base16string = arr.map(item => item.toString(16));

console.log(base16string);
.as-console-wrapper {min-height: 100%!important; top: 0}


推荐阅读