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

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

Description

bytes To Hex

License

Open Source License

Declaration

private static String bytesToHex(byte[] bt) 

Method Source Code

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

public class Main {

    private static String bytesToHex(byte[] bt) {
        StringBuilder stringBuilder = new StringBuilder();
        if (bt == null || bt.length <= 0) {
            return null;
        }//  ww w.j a v a 2 s .  c  om
        for (int i = 0; i < bt.length; i++) {
            int v = bt[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();
    }
}

Related

  1. bytesToHex(byte[] b)
  2. bytesToHex(byte[] b)
  3. bytesToHex(byte[] b, int offset, int length)
  4. bytesToHex(byte[] binary)
  5. bytesToHex(byte[] bs, int off, int length)
  6. bytesToHex(byte[] buf)
  7. bytesToHex(byte[] bytes)
  8. bytesToHex(byte[] bytes)
  9. bytesToHex(byte[] bytes)