0

I am continuously getting data from remote bluetooth device which I am storing in a buffer readBuf.

I copy this readBuf to buf.

System.arraycopy(readBuf, 0, buf, 0, readBuf.length);

Now my buf contains data such that -

buf[0] == 0x7D 

buf[1] == 0x51

buf[2] == 0x42 

...and so on...

I want to log this data to know what is coming from remote bluetooth device.

I tried,

Log.i(TAG, "Buffer Data---- "+Arrays.toString(buf));

But it is not giving data correctly to be 7D 51 42 and so on....

How to get the data in order to log ?

sjain
  • 23,126
  • 28
  • 107
  • 185

2 Answers2

0

This is working fine -

    StringBuffer bufData = new StringBuffer();
    for(byte b : readBuf)
    {
        bufData.append(String.format("%02X", b));
        bufData.append(" ");
    }

    Log.i(TAG, "Data Coming from Remote Device---"+bufData.toString());
sjain
  • 23,126
  • 28
  • 107
  • 185
0

Arrays.toString(byte[])

Works fine, although what you are seeing is an signed integer representation of each byte. That's because in Java all integers are signed with a Two's Complement .

You can learn a lot on how to convert bytes to hex in this answer.

Community
  • 1
  • 1
ehanoc
  • 2,187
  • 18
  • 23