简体   繁体   English

转储字节数组为十六进制值

[英]Dump byte array as hexadecimal values

In JavaScript on Firefox, a Uint8Array shows like this on the console, using console.log : 在Firefox上的JavaScript中,使用console.log在控制台上显示如下Uint8Array:

Uint8Array […]
0: 131
1: 165
2: 116
3: 111
4: 112

How can I make it show as hexadecimal values, like this: 我如何使其显示为十六进制值,如下所示:

Uint8Array […]
0: 0x83
1: 0xa5
2: 0x74
3: 0x6f
4: 0x70

I'm trying to debug some websocket communication and have to look up the bytes in the format specification which only lists the values in hex. 我正在尝试调试一些websocket通信,并且不得不在格式规范中查找字节,该格式规范仅以十六进制列出值。

You can't make the console do that (at least I know of no way to do that), but you could transform the array explicitly: 您不能使控制台做到这一点(至少我不知道这样做),但是您可以显式地转换数组:

console.log([].map.call(yourArray, x => x.toString(16))

edit — thanks for the correction; 编辑 -感谢您的纠正; the typed arrays return new typed arrays from their .map() . 类型化数组从其.map()返回新的类型化数组。

You could also make it a regular array with Array.from() . 您也可以使用Array.from()将其设置为常规数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM