0

I work with my custom USB Device. I get from it bytes array. I want to display this array as hex string so I convert it firstly into Long like this :

byte[] receivedTag = connector.receive(512);
                        String tag = null;
                        if (receivedTag != null) {
                            long tagValue = ByteBuffer.wrap(receivedTag).getLong();

Next I want to convert it into hex String :

 tag = Long.toHexString(tagValue);

however I've got problem here. Received Tag has something about 400 bytes (I've checked it on debug) , but when I convert it , tag is only 16 chars long(8 bytes, there are correct). Why is that ?

Bartos
  • 1,007
  • 3
  • 15
  • 38

1 Answers1

1
public static String bytesToHex(byte[] in) {
    final StringBuilder builder = new StringBuilder();
    for(byte b : in) {
        builder.append(String.format("%02x", b));
    } 
    return builder.toString();
}  

// consider using this

Muddassir Ahmed
  • 518
  • 4
  • 19
  • It's better right now, but still got something about half of the bytes that should be converted - rest of them is 0 ( they shouldn't be). – Bartos Jul 18 '16 at 10:10