Android Utililty Methods Hex String to Byte Array Convert

List of utility methods to do Hex String to Byte Array Convert

Description

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

Method

StringfromHex(String hex)
from Hex
return new String(toByte(hex));
StringfromHex(String hex)
Get the string based on the hex format
return new String(toByte(hex));
byte[]hexToBytes(String str)
hex To Bytes
if (str == null) {
    return null;
} else if (str.length() < 2) {
    return null;
} else {
    int len = str.length() / 2;
    byte[] buffer = new byte[len];
    for (int i = 0; i < len; i++) {
...
byte[]hexToByte(String input)
hex To Byte
byte[] output = new byte[input.length() / 2];
String input2 = input.toLowerCase();
for (int i = 0; i < input2.length(); i += 2) {
    output[i / 2] = hexToByte(input2.charAt(i),
            input2.charAt(i + 1));
return output;
byte[]hexToBytes(String hexString)
Takes a string in hexidecimal format and converts it to a binary byte array.
byte[] result = new byte[hexString.length() / 2];
for (int i = 0; i < result.length; ++i) {
    int offset = i * 2;
    result[i] = (byte) Integer.parseInt(
            hexString.substring(offset, offset + 2), 16);
return result;
bytehexToByte(char char1, char char2)
hex To Byte
byte output = 0x00;
if (char1 == '0') {
    output = 0x00;
} else if (char1 == '1') {
    output = 0x10;
} else if (char1 == '2') {
    output = 0x20;
} else if (char1 == '3') {
...
byte[]hexStringToByteArray(String s)
hex String To Byte Array
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
    data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character
            .digit(s.charAt(i + 1), 16));
return data;
byte[]hexStringToBytes(String s)
hex String To Bytes
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
    data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character
            .digit(s.charAt(i + 1), 16));
return data;
byte[]hex2bytes(String hex)
hexbytes
byte[] bytes = new byte[hex.length() / 2];
for (int i = 0; i < bytes.length; i++) {
    bytes[i] = (byte) Integer.parseInt(
            hex.substring(i * 2, (i + 1) * 2), 16);
return bytes;
byte[]hexStr2ByteArr(String paramString)
hex Str Byte Arr
byte[] arrayOfByte1 = paramString.getBytes();
int i = arrayOfByte1.length;
byte[] arrayOfByte2 = new byte[i / 2];
for (int j = 0; j < i; j += 2) {
    String str = new String(arrayOfByte1, j, 2);
    arrayOfByte2[(j / 2)] = (byte) Integer.parseInt(str, 16);
return arrayOfByte2;
...