Android Utililty Methods Byte Array to Hex Convert

List of utility methods to do Byte Array to Hex Convert

Description

The list of methods to do Byte Array to Hex Convert are organized into topic(s).

Method

StringbyteArrayToHexString(byte[] bytes)
byte Array To Hex String
int oldLength = bytes.length;
byte[] positiveBytes = new byte[oldLength + 1];
System.arraycopy(bytes, 0, positiveBytes, 1, oldLength);
positiveBytes[0] = 1;
BigInteger bigInt = new BigInteger(positiveBytes);
String hex = bigInt.toString(16);
return hex.substring(1);
StringbytesToHex(byte[] data)
Convenience method to convert a byte array to a hex string.
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
    buf.append(byteToHex(data[i]).toUpperCase());
return (buf.toString());
StringconvertToHex(byte[] in)
convert To Hex
StringBuilder builder = new StringBuilder(in.length * 2);
Formatter formatter = new Formatter(builder);
for (byte inByte : in)
    formatter.format("%02x", inByte);
formatter.close();
return formatter.toString();
StringconvertToHex(byte[] raw)
convert To Hex
final StringBuilder hex = new StringBuilder(raw.length * 2);
for (final byte b : raw) {
    hex.append(HEX_DIGITS.charAt((b & 0xF0) >> 4)).append(
            HEX_DIGITS.charAt((b & 0x0F)));
return hex.toString();
Stringbytes2Hex(byte[] bts)
bytes Hex
String des = "";
String tmp = null;
for (int i = 0; i < bts.length; i++) {
    tmp = (Integer.toHexString(bts[i] & 0xFF));
    if (tmp.length() == 1) {
        des += "0";
    des += tmp;
...
Stringbytes2HexString(byte[] bytes)
bytes Hex String
if (bytes == null)
    return null;
StringBuilder ret = new StringBuilder(2 * bytes.length);
for (int i = 0; i < bytes.length; i++) {
    int b;
    b = 0x0f & (bytes[i] >> 4);
    ret.append("0123456789ABCDEF".charAt(b));
    b = 0x0f & bytes[i];
...
Stringbytes2hex(byte[] bytes)
byteshex
StringBuffer strbuf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    int bt = bytes[i] & 0xff;
    if (bt < 0x10) {
        strbuf.append("0");
    strbuf.append(Integer.toHexString(bt));
return strbuf.toString();
StringbytesToHex(byte[] bytes)
Convert Byte array to Hex (string)
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
    int v = bytes[j] & 0xFF;
    hexChars[j * 2] = hexArray[v >>> 4];
    hexChars[j * 2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);
StringbytesToHex(byte[] data)
Convenience method to convert a byte array to a hex string.
StringBuilder buf = new StringBuilder();
for (int i = 0; i < data.length; i++) {
    buf.append(byteToHex(data[i]).toUpperCase());
return (buf.toString());
StringbytesToHex(byte[] data)
bytes To Hex
return bytesToHex(data, 0, data.length);