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

StringgetHexString(byte[] b, String splitString)
get Hex String
int[] intArray = new int[b.length];
for (int i = 0; i < b.length; i++) {
    if (b[i] < 0) {
        intArray[i] = b[i] + 256;
    } else {
        intArray[i] = b[i];
return getHexString(intArray, splitString);
StringtoHex(byte[] b)
to Hex
StringBuilder sb = new StringBuilder();
Formatter fmt = new Formatter(sb, Locale.US);
for (int i = 0; i < b.length; ++i) {
    fmt.format("%02X", b[i]);
return fmt.toString();
StringbytesToHexString(byte[] bytes)
bytes To Hex String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    String hex = Integer.toHexString(0xFF & bytes[i]);
    if (hex.length() == 1) {
        sb.append('0');
    sb.append(hex);
return sb.toString();
StringhexToHexString(byte[] b)
hex To Hex String
int len = b.length;
int[] x = new int[len];
String[] y = new String[len];
StringBuilder str = new StringBuilder();
int j = 0;
for (; j < len; j++) {
    x[j] = b[j] & 0xff;
    y[j] = Integer.toHexString(x[j]);
...
StringtoHexString(byte[] b)
to Hex String
char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
        '9', 'A', 'B', 'C', 'D', 'E', 'F' };
StringBuilder sb = new StringBuilder(b.length * 2);
for (int i = 0; i < b.length; i++) {
    sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
    sb.append(HEX_DIGITS[b[i] & 0x0f]);
return sb.toString();
...
StringbytesToHexString(byte[] src)
bytes To Hex String
StringBuilder stringBuilder = new StringBuilder("");
if (src == null || src.length <= 0) {
    return null;
for (int i = 0; i < src.length; i++) {
    int v = src[i] & 0xFF;
    String hv = Integer.toHexString(v);
    if (hv.length() < 2) {
...
StringConvertHexString(byte[] b)
Convert Hex String
String a = "";
for (int i = 0; i < b.length; i++) {
    String hex = Integer.toHexString(b[i] & 0xFF);
    if (hex.length() == 1) {
        hex = '0' + hex;
    a = a + hex;
return a;
StringgetHexStringOfByte(byte[] bytes)
get Hex String Of Byte
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    int val = (bytes[i]) & 0xff;
    if (val < 16) {
        hexValue.append("0");
    hexValue.append(Integer.toHexString(val));
return hexValue.toString();
StringbytesToHexString(byte[] bytes)
bytes To Hex String
StringBuffer sb = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    String hex = Integer.toHexString(0xFF & bytes[i]);
    if (hex.length() == 1) {
        sb.append('0');
    sb.append(hex);
return sb.toString();
StringbytesToHexString(byte[] bytes)
bytes To Hex String
StringBuilder sb = new StringBuilder("");
if (bytes == null || bytes.length <= 0) {
    return null;
for (int i = 0; i < bytes.length; i++) {
    int v = bytes[i] & 0xFF;
    String hv = Integer.toHexString(v);
    if (hv.length() < 2) {
...