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

StringbytesToHex(byte[] data, int offset, int length)
bytes To Hex
if (length <= 0) {
    return "";
StringBuilder hex = new StringBuilder();
for (int i = offset; i < offset + length; i++) {
    hex.append(String.format(" %02X", data[i] % 0xFF));
hex.deleteCharAt(0);
...
StringbytesToHexString(byte[] bytes)
bytes To Hex String
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++) {
    v = bytes[j] & 0xFF;
    hexChars[j * 2] = hexArray[v >>> 4];
    hexChars[j * 2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);
...
StringbytesToHexString(byte[] bytes)
bytes To Hex String
StringBuilder sb = new StringBuilder();
for (byte aByte : bytes) {
    String hex = Integer.toHexString(0xFF & aByte);
    if (hex.length() == 1) {
        sb.append('0');
    sb.append(hex);
return sb.toString();
StringbytesToHexString(byte[] bytes)
bytes To Hex String
StringBuilder sb = new StringBuilder();
for (byte aByte : bytes) {
    String hex = Integer.toHexString(0xFF & aByte);
    if (hex.length() == 1) {
        sb.append('0');
    sb.append(hex);
return sb.toString();
StringbytesToHexString(byte[] bytes)
bytes To 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];
...
Stringbyte2HexStr(byte[] b)
byte Hex Str
String hs = "0x";
String stmp = "";
for (int n = 0; n < b.length; n++) {
    stmp = (Integer.toHexString(b[n] & 0XFF));
    if (stmp.length() == 1)
        hs = hs + "0" + stmp;
    else
        hs = hs + stmp;
...
Stringbyte2HexStr(byte[] b, int length)
byte Hex Str
String hs = "";
String stmp = "";
for (int n = 0; n < length; ++n) {
    stmp = Integer.toHexString(b[n] & 0xFF);
    if (stmp.length() == 1)
        hs = hs + "0" + stmp;
    else {
        hs = hs + stmp;
...
Stringbyte2HexString(byte[] b)
byte Hex String
StringBuffer sb = new StringBuffer();
int length = b.length;
for (int i = 0; i < b.length; i++) {
    String stmp = Integer.toHexString(b[i] & 0xff);
    if (stmp.length() == 1)
        sb.append("0" + stmp);
    else
        sb.append(stmp);
...
Stringbyte2Hext(byte bin)
byte Hext
int i = bin & 0xFF;
return Integer.toHexString(i);
StringbyteArr2HexStr(byte[] arr)
byte Arr Hex Str
int iLen = arr.length;
StringBuffer sb = new StringBuffer(iLen * 2);
for (int i = 0; i < iLen; i++) {
    int intTmp = arr[i];
    while (intTmp < 0) {
        intTmp = intTmp + 256;
    if (intTmp < 16) {
...