Java Byte Array to Hex bytesToHex(byte[] data)

Here you can find the source of bytesToHex(byte[] data)

Description

bytes To Hex

License

Open Source License

Declaration

public static String bytesToHex(byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String bytesToHex(byte[] data) {
        return bytesToHex(data, 0, data.length);
    }/*from ww  w  .java  2  s .c  o m*/

    public static String bytesToHex(byte[] data, int offset, int length) {
        if (length <= 0) {
            return "";
        }

        StringBuilder hex = new StringBuilder();
        for (int i = offset; i < offset + length; i++) {
            hex.append(String.format(" %02X", data[i] % 0xFF));
        }
        hex.deleteCharAt(0);
        return hex.toString();
    }
}

Related

  1. bytesToHex(byte[] bytes, byte[] hex, int offset)
  2. bytesToHex(byte[] bytes, int groupSize)
  3. bytesToHex(byte[] bytes, int size, char delim)
  4. bytesToHex(byte[] data)
  5. bytesToHex(byte[] data)
  6. bytesToHex(byte[] data)
  7. bytesToHex(byte[] data)
  8. bytesToHex(byte[] data, char[] chars)
  9. bytesToHex(byte[] data, int m, int n)