melisa zand
melisa zand

Reputation: 211

java : converting hexadecimal number string to decimal

I receive hexadecimal number string from Matlab into my device . I check the data that is send via 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`. [email protected]`.
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   [email protected]@. ..@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.... [email protected]@.
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   

I receive this data (byte[]) here :

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

and here is what my device shows on the screen even before converting hexa to decimal :

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 

totally nonsense ! anybody knows why the device shows this nonsense? does it convert hexadecimal itself to this format ?

for example I send 0 23 23 12 33 (xpc target udp send binary block)

in wire shark :

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                                              @@               

but in the mobile screen :

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

Upvotes: 0

Views: 1250

Answers (1)

aioobe
aioobe

Reputation: 421350

You havn't told us what type data has, but presumably it is byte[].

What would you expect from the following code

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

Obviously you'll get a bunch of numbers.

Try using new String(data).

Upvotes: 1

Related Questions