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[]byteArrayFromBytes(int... bytes)
Return an array of bytes containing as elements this method's parameters.
int length = bytes.length;
byte[] byteArray = new byte[length];
for (int i = 0; i < length; i++)
    byteArray[i] = (byte) bytes[i];
return byteArray;
byte[]byteArrayFromChar(char i)
byte Array From Char
byte[] out = new byte[2];
charIntoByteArray(i, 0, out);
return out;
byte[]byteArrayFromHexString(String in)
Convert an hex-string to byte array "0001a0" -> {0x00, 0x01, 0xa0}
byte out[] = new byte[in.length() / 2];
for (int i = 0; i < in.length(); i += 2) {
    out[i / 2] = (byte) Integer.parseInt(in.substring(i, i + 2), 16);
return out;
byte[]byteArrayFromInt(final int number)
byte Array From Int
final byte b0 = (byte) (0xff & number);
final byte b1 = (byte) (0xff & (number >> 8));
final byte b2 = (byte) (0xff & (number >> 16));
final byte b3 = (byte) (0xff & (number >> 24));
return new byte[] { b3, b2, b1, b0 };
byte[]byteArrayFromInteger(int integer)
Convert an integer value into the corresponding byte array
return new byte[] { (byte) (integer >> 24), (byte) (integer >> 16), (byte) (integer >> 8), (byte) integer };
byte[]byteArrayFromInteger(int integer)
byte Array From Integer
return new byte[] { (byte) (integer >> 24), (byte) (integer >> 16), (byte) (integer >> 8), (byte) integer };
byte[]bytes(final byte... elements)
bytes
return elements;
byte[]bytes(final int... ints)
bytes
byte[] b = new byte[ints.length * 4];
for (int i = 0; i < ints.length; i++) {
    int offset = i * 4;
    b[offset] = (byte) (ints[i] >> 24);
    b[offset + 1] = (byte) (ints[i] >> 16);
    b[offset + 2] = (byte) (ints[i] >> 8);
    b[offset + 3] = (byte) (ints[i]);
return b;
byte[]bytes(int... bytes)
bytes
byte[] result = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) {
    result[i] = (byte) bytes[i];
return result;
byte[]bytes(int... ints)
bytes
byte[] b = new byte[ints.length];
for (int i = 0; i < ints.length; i++) {
    b[i] = (byte) (checkBounds(ints[i], 0, 256) & 0xFF);
return b;