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

StringconvertToHex(byte[] data)
convert To Hex
StringBuilder buf = new StringBuilder();
for (byte b : data) {
    int halfbyte = (b >>> 4) & 0x0F;
    int two_halfs = 0;
    do {
        buf.append((0 <= halfbyte) && (halfbyte <= 9) ? (char) ('0' + halfbyte)
                : (char) ('a' + (halfbyte - 10)));
        halfbyte = b & 0x0F;
...
StringtoHex(final byte[] bytes)
to Hex
if (bytes == null) {
    return "";
StringBuffer sb = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; ++i) {
    appendHex(sb, bytes[i]);
return sb.toString();
...
StringbyteArrayToHexString(byte[] b)
byte Array To Hex String
String result = "";
for (int i = 0; i < b.length; i++) {
    result += Integer.toString((b[i] & 0xff) + 0x100, 16)
            .substring(1);
return result;
StringtoHexString(byte abyte0[], int beginIndex, int endIndex, boolean spaceFlag)
to Hex String
if (null == abyte0)
    return null;
if (0 == abyte0.length)
    return "";
StringBuffer sbuf = new StringBuffer();
appendHex(sbuf, abyte0[beginIndex]);
for (int i = (beginIndex + 1); i < endIndex; i++) {
    if (spaceFlag)
...
StringtoHexString(byte abyte0[], int beginIndex, int endIndex)
to Hex String
if (null == abyte0)
    return null;
return toHexString(abyte0, beginIndex, endIndex, true);
StringtoHexString(byte abyte0[], boolean spaceFlag)
to Hex String
if (null == abyte0)
    return null;
return toHexString(abyte0, 0, abyte0.length, spaceFlag);
StringtoHexString(byte abyte0[])
Method convert byte[] to HexString
if (null == abyte0)
    return null;
return toHexString(abyte0, 0, abyte0.length, true);
StringtoHexString(byte[] bytes)

Given an array of bytes, it will return the representation as a string of hex data.

StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    byte b = bytes[i];
    sb.append(new char[] { HEX_CHARS[(b >> 4) & 0x0f],
            HEX_CHARS[b & 0x0f] });
return sb.toString();
StringencodeHexStr(final byte[] bytes)
encode Hex Str
if (bytes == null) {
    return null;
char[] result = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
    result[i * 2] = digital[(bytes[i] & 0xf0) >> 4];
    result[i * 2 + 1] = digital[bytes[i] & 0x0f];
return new String(result);
StringbyteArrayToHexString(byte[] b)
byte Array To Hex String
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
    resultSb.append(byteToHexString(b[i]));
return resultSb.toString();