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

Stringbyte2hex(byte[] b)
bytehex
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
    stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
    if (stmp.length() == 1)
        hs = hs + "0" + stmp;
    else
        hs = hs + stmp;
...
Stringbyte2hex(byte[] buffer)
bytehex
String h = "";
for (int i = 0; i < buffer.length; i++) {
    String temp = Integer.toHexString(buffer[i] & 0xFF);
    if (temp.length() == 1) {
        temp = "0" + temp;
    h = h + " " + temp;
return h;
Stringbyte2hex(byte[] buffer, int len)
bytehex
String h = "";
for (int i = 0; i < len; i++) {
    String temp = Integer.toHexString(buffer[i] & 0xFF);
    if (temp.length() == 1) {
        temp = "0" + temp;
    h = h + " " + temp;
return h;
Stringbyte2hexWithoutSpace(byte[] buffer)
bytehex Without Space
String h = "";
for (int i = 0; i < buffer.length; i++) {
    String temp = Integer.toHexString(buffer[i] & 0xFF);
    if (temp.length() == 1) {
        temp = "0" + temp;
    h = h + temp;
return h;
StringbyteArrayToHexString(byte[] b)
byte Array To Hex String
StringBuffer sb = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++) {
    int v = b[i] & 0xff;
    if (v < 16) {
        sb.append('0');
    sb.append(Integer.toHexString(v));
return sb.toString().toUpperCase();
StringbyteArrayToHexString(final byte[] array)
Gets a pretty representation of a Byte Array as a HEX String.
final StringBuffer sb = new StringBuffer();
boolean firstEntry = true;
sb.append('[');
for (final byte b : array) {
    if (!firstEntry) {
        sb.append(", ");
    sb.append(HEXES.charAt((b & 0xF0) >> 4));
...
StringbyteToHexString(Byte b)
Converts a byte to the HEX String representation.
return String.format("%02X", b);
StringbyteToHexString(byte b)
byte To Hex String
int n = b;
if (n < 0) {
    n = 256 + n;
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
StringbyteToHexString(byte value)
byte To Hex String
int unsigned = value & 0xFF;
return "" + hexArray[unsigned >>> 4] + hexArray[unsigned & 0x0F];
StringbytesToHex(byte[] bytes)
bytes To Hex
return toHexString(bytes, 0, bytes.length);