Java Byte Array to Hex String bytesToHexString(byte[] bArray)

Here you can find the source of bytesToHexString(byte[] bArray)

Description

bytes To Hex String

License

Apache License

Declaration

public static final String bytesToHexString(byte[] bArray) 

Method Source Code

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

public class Main {
    private static final char[] ac = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    public static final String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);

        for (int i = 0; i < bArray.length; i++) {
            String sTemp = byteToHexString(bArray[i]);
            sb.append(sTemp.toUpperCase());
        }//from   www . jav  a2 s  .com
        return sb.toString();
    }

    private static String byteToHexString(byte b) {
        char[] ch = new char[2];
        ch[0] = ac[(b >>> 4 & 0xF)];
        ch[1] = ac[(b & 0xF)];
        String s = new String(ch);
        return new String(ch);
    }
}

Related

  1. bytesToHexString(byte[] _bytes)
  2. bytesToHexString(byte[] array)
  3. bytesToHexString(byte[] b)
  4. bytesToHexString(byte[] b, int length)
  5. bytesToHexString(byte[] bArray)
  6. bytesToHexString(byte[] bs)
  7. bytesToHexString(byte[] buf)
  8. bytesToHexString(byte[] byteArray)
  9. bytesToHexString(byte[] bytes)