Java Utililty Methods Byte Array Create

List of utility methods to do Byte Array Create

Description

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

Method

byte[]toByteArray(String hex)
Convert a hexadecimal string into its byte representation.
hex = hex.toLowerCase();
byte[] buf = new byte[hex.length() / 2];
int j = 0;
for (int i = 0; i < buf.length; i++) {
    buf[i] = (byte) ((Character.digit(hex.charAt(j++), 16) << 4) | Character.digit(hex.charAt(j++), 16));
return buf;
byte[]toByteArray(String hex)
Convert hex string to byte array
byte[] byteArray = new byte[hex.length() / 2];
for (int i = 0; i < byteArray.length; i++) {
    byteArray[i] = (byte) Integer.parseInt(hex.substring((i * 2), ((i * 2) + 2)), 16);
return byteArray;
byte[]toByteArray(String hexStr)
to Byte Array
if (hexStr.length() < 1)
    return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
    int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
    int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
    result[i] = (byte) (high * 16 + low);
return result;
byte[]toByteArray(String hexString)
to Byte Array
byte[] buffer = new byte[hexString.length() / 2];
for (int i = 0; i < buffer.length; i++)
    buffer[i] = toByte(hexString.substring(2 * i, 2 * i + 2));
return buffer;
byte[]toByteArray(String hexString)
Get byte array from hex string
int arrLength = hexString.length() >> 1;
byte buff[] = new byte[arrLength];
for (int i = 0; i < arrLength; i++) {
    int index = i << 1;
    String digit = hexString.substring(index, index + 2);
    buff[i] = (byte) Integer.parseInt(digit, 16);
return buff;
...
byte[]toByteArray(String hexString)
toHexString - generate a byte array representation of the specified string
if ((hexString.length() % 2) == 1) {
    return null;
try {
    int idx = 0;
    byte result[] = new byte[hexString.length() / 2];
    for (int i = 0; i < hexString.length(); i += 2) {
        String val = hexString.substring(i, i + 2);
...
byte[]toByteArray(String map)
to Byte Array
int[] values = toIntArray(map);
if (values == null) {
    return null;
byte[] bytes = new byte[values.length];
for (int i = 0; i < values.length; i++) {
    bytes[i] = (byte) values[i];
return bytes;
byte[]toByteArray(String s)
Konvertiert einen Hex-String mit zwei Hex-Zeichen je Byte in ein Byte-Array.
byte[] ba = new byte[s.length() / 2];
for (int i = 0; i < ba.length; i++) {
    ba[i] = toByte(s.substring(2 * i, 2 * i + 2));
return ba;
byte[]toByteArray(String source)
Parses a string containing hex numbers to a byte array.
String s = source.replaceAll(" |\n", "");
byte[] b = new byte[s.length() / 2];
if ((s.length() % 2) != 0) {
    throw new IllegalArgumentException("need even number of hex double digits [" + s.length() + "]");
for (int i = 0; i < s.length(); i += 2) {
    String q = s.substring(i, i + 2);
    b[i / 2] = (byte) Integer.parseInt(q, 16);
...
byte[]toByteArray(String str)
to Byte Array
byte[] result = new byte[str.length() + 1];
for (int i = 0; i < str.length(); i++) {
    result[i] = (byte) str.charAt(i);
result[str.length()] = 0;
return result;