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

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

Description

bytes To Hex

License

Apache License

Declaration

public static String bytesToHex(byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String bytesToHex(byte[] b) {
        char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        StringBuffer buf = new StringBuffer();
        for (int j = 0; j < b.length; j++) {
            buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
            buf.append(hexDigit[b[j] & 0x0f]);
        }/* w  ww  . j a v  a2 s  . co  m*/

        return buf.toString();
    }

    public static String toString(Object obj) {
        if (null == obj)
            return null;

        return String.valueOf(obj);
    }
}

Related

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