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(final String hexString)
Converts the given hex string to byte array
final int length = hexString.length();
final byte[] bytes = new byte[length / 2];
for (int i = 0; i < length; i += 2) {
    bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
            + Character.digit(hexString.charAt(i + 1), 16));
return bytes;
byte[]toByteArray(int data)
Convert int to byte array
return new byte[] { (byte) ((data >> 24) & 0xff), (byte) ((data >> 16) & 0xff), (byte) ((data >> 8) & 0xff),
        (byte) ((data >> 0) & 0xff) };
byte[]toByteArray(int i)
to Byte Array
byte[] bytes = new byte[4];
bytes[0] = (byte) ((i >>> 24) & 0xFF);
bytes[1] = (byte) ((i >>> 16) & 0xFF);
bytes[2] = (byte) ((i >>> 8) & 0xFF);
bytes[3] = (byte) (i & 0xFF);
return bytes;
byte[]toByteArray(int in)
to Byte Array
byte[] out = new byte[4];
out[0] = (byte) in;
out[1] = (byte) (in >> 8);
out[2] = (byte) (in >> 16);
out[3] = (byte) (in >> 24);
return out;
byte[]toByteArray(int in, int size)
to Byte Array
byte[] bytes = new byte[size];
for (int i = size - 1; i >= 0; i--) {
    bytes[(size - 1) - i] = (byte) (in >>> 8 * i);
return bytes;
byte[]toByteArray(int intr)
This method converts one integer number to little-endian byte array.
byte[] result = new byte[4];
for (int i = 0; i < 4; ++i) {
    result[i] = (byte) (intr & OP_PATTERN);
    intr = (intr >>> 8);
return result;
byte[]toByteArray(int num)
to Byte Array
final int INT_BYTES = Integer.SIZE / 8;
byte[] bytes = new byte[INT_BYTES];
for (int i = 0; i < INT_BYTES; i++) {
    bytes[(INT_BYTES - 1) - i] = (byte) (num >>> 8 * i);
return bytes;
byte[]toByteArray(int value)
Convert an integer to a byte[] array.
int intByteSize = 4;
byte[] byteArray = new byte[intByteSize];
for (int i = 0; i < intByteSize; i++) {
    byteArray[i] = (byte) ((value) >>> ((intByteSize - 1 - i) * 8));
return byteArray;
byte[]toByteArray(int value)
to Byte Array
byte[] array = new byte[4];
putIntInByteArray(value, array, 0);
return array;
byte[]toByteArray(int value)
Gets int value as byte array.
return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value };