javascript - Javascript:十六进制到字符串,无需转换为 ascii、int 或 xyz
问题描述
我有一个字节数组
sensor_id = [bytes[36],bytes[35],bytes[34],bytes[33]]
它包含以下十六进制
0x69, 0x72, 0x33, 0x88
我需要将 69 72 33 88 合并到没有对话 =>“69723388”的字符串值。
感谢您的帮助
解决方案
您可以使用 将十六进制值转换为字符串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}
推荐阅读
- rust - 如何为使用生命周期实现的特征传递函数?
- swagger - 大摇大摆的模式数组
- for-loop - 嵌套 For 循环 astrix 模式
- firebase - 在查询中使用 FieldPath 设置 redux-firestore 监听器
- python-3.x - 在ubuntu上没有pip的python安装
- javascript - 如果表格行直到下一个表格标题被隐藏,则隐藏表格标题
- javascript - 字典的请求一直以 Str 的形式出现,我怎样才能让它作为字典通过?
- sql-server - T-SQL - 查找具有时间间隔的记录
- hyperlink - 在活动链接上禁用悬停
- ios - DUXPreFlightStatusWidget 和 DUXPreflightChecklistController 之间的交互没有像宣传的那样工作