Hex to String in Android (Java)?

Maybe I was sticky in hex for String? I do not know. my code is:

final byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA);

Should txValue be a byte?

debugging:

Log.d("p1", ""+txValue.toString());

then show me those:

[B@1e631929
[B@9264ae

I do not know how to fix this? Does anyone help me?

+4
source share
3 answers

You should use the public String(byte[] bytes)constructor:

Creates a new line by decoding the specified byte array using the default platform encoding. The length of a new line is a function of the encoding and, therefore, cannot be equal to the length of the byte array.

String s = new String(txValue);

and then type s, it contains what you want.

txValue txValue.toString() .

+1

: final byte [] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA);

final int GasValue = ((txValue [0] < 8) | (txValue [1] & 0xff)) & 0xffff;

= Integer.toString(GasValue);

Log.d( "p1", "" + );

OK

0

You should use Arrays.toString (txValue)

This is how i use i code

 final byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA);
   txtResult.setText(Arrays.toString(txValue));

The result is as follows: [27,0,1,13,13,4,5]

0
source

All Articles