0

我从 Matlab 接收十六进制数字字符串到我的设备中。我检查通过 wireshark 发送的数据:

0000  00 16 cf 5c 0d c2 ec 55  f9 44 c8 9b 08 00 45 00   ...\...U .D....E.
0010  00 dc 1c f9 00 00 80 11  9b 9a c0 a8 00 16 c0 a8   ........ ........
0020  00 17 04 bd 0b b8 00 c8  e5 1a 40 46 6c cc c0 00   ........ ..@Fl...
0030  00 00 3f e6 66 66 60 00  00 00 40 62 1e 66 60 00   ..?.ff`. ..@b.f`.
0040  00 00 bf c9 99 99 a0 00  00 00 40 4d c0 00 00 00   ........ ..@M....
0050  00 00 40 0f 33 33 40 00  00 00 40 6f e0 00 00 00   ..@.33@. ..@o....
0060  00 00 40 59 80 00 00 00  00 00 40 46 6c cc c0 00   ..@Y.... ..@Fl...
0070  00 00 3f d9 99 99 a0 00  00 00 40 6f e0 00 00 00   ..?..... ..@o....
0080  00 00 40 59 80 00 00 00  00 00 40 48 b3 33 40 00   ..@Y.... ..@H.3@.
0090  00 00 3f f4 cc cc c0 00  00 00 40 50 e9 99 a0 00   ..?..... ..@P....
00a0  00 00 40 11 cc cc c0 00  00 00 40 6f e0 00 00 00   ..@..... ..@o....
00b0  00 00 c0 39 99 99 a0 00  00 00 40 6f e0 00 00 00   ...9.... ..@o....
00c0  00 00 c0 39 99 99 a0 00  00 00 40 6f e0 00 00 00   ...9.... ..@o....
00d0  00 00 c0 39 99 99 a0 00  00 00 40 6f e0 00 00 00   ...9.... ..@o....
00e0  00 00 c0 39 99 99 a0 00  00 00   

我在这里收到这个数据(字节[]):

receiveddata += str(data[i]) + " ";

这是我的设备在将十六进制转换为十进制之前在屏幕上显示的内容:

64 71 32 0 0 0 0 0 -65 -39 -103 -103 -96 0 0 0 64 89 -93 51 64 0 0 0 -64 0 -52 -52 -64 0 0 0 64 86 -68 -52 -64 0 0 0 63 -10 102 102 96 0 0 0 64 100 120 0 0 0 0 0 -64 26 -52 -52 -64 0 0 0 64 70 108 -52 -64 0 0 0 63 -39 -103 -103 -96 0 0 0 64 111 -32 0 0 0 0 0 64 89 -128 0 0 0 0 0 64 71 -7 -103 -96 0 0 0 0 0 0 0 0 0 0 0 64 111 -32 0 0 0 0 0 -64 57 -103 -103 -96 0 0 0 64 111 -32 0 0 0 0 0 -64 57 -103 -103 -96 0 0 0 64 111 -32 0 0 0 0 0 -64 57 -103 -103 -96 0 0 0 64 111 -32 0 0 0 0 0 -64 57 -103 -103 -96 0 0 0 64 111 -32 0 0 0 0 0 -64 57 -103 -103 -96 0 0 0 

完全是胡说八道!有人知道为什么设备会显示这种废话吗?它会将十六进制本身转换为这种格式吗?

例如我发送 0 23 23 12 33 (xpc 目标 udp 发送二进制块)

在钢丝鲨中:

0000  00 16 cf 5c 0d c2 00 22  69 86 14 f3 08 00 45 00   ...\..." i.....E.
0010  00 44 85 66 00 00 80 11  33 c1 c0 a8 00 17 c0 a8   .D.f.... 3.......
0020  00 1a 08 87 0b b8 00 30  92 4c 00 00 00 00 00 00   .......0 .L......
0030  00 00 00 00 00 00 00 00  37 40 00 00 00 00 00 00   ........ 7@......
0040  37 40 00 00 00 00 00 00  28 40 00 00 00 00 00 80   7@...... (@......
0050  40 40                                              @@               

但在手机屏幕上:

000000000000000 55 64 000000 55 64000000 40 64..............
4

1 回答 1

1

你还没有告诉我们有什么类型data,但大概是byte[].

您对以下代码有何期望

byte b = 42;
String receiveddata = "" + b;

显然你会得到一堆数字。

尝试使用new String(data).

于 2012-05-23T09:21:32.757 回答