You can use BigInteger
:
From Integers:
byte[] array = BigInteger.valueOf(0xAABBCCDD).toByteArray();
System.out.println(Arrays.toString(array))
// --> {-86, -69, -52, -35 }
The returned array is of the size that is needed to represent the number, so it could be of size 1, to represent 1 for example. However, the size cannot be more than four bytes if an int is passed.
From Strings:
BigInteger v = new BigInteger("AABBCCDD", 16);
byte[] array = v.toByteArray();
However, you will need to watch out, if the first byte is higher 0x7F
(as is in this case), where BigInteger would insert a 0x00 byte to the beginning of the array. This is needed to distinguish between positive and negative values.