Int array to byte array

Dear Team,

I have a question of transfer a known int array to its byte version.

Assume that iArray is the known int Array with fixed elements and length. Can I transfer it to its byte version like the following steps…

	byte[] bArray = new byte[iArray.length];
	for (int i = 0; i < bArray.length; i++ ) {
		bArrayl[i] = (byte) iArray[i];

saw other ways online…but they are kind of complicated…
will this “brutal” method cause some problems or it is correct…I implemented this in my java compiler…its output war the same as the int-type one…but I am still not sure whether it is okay.

thanks in advance.

If you are asking if (byte) int_val is the byte representation of the number, then yes:

I just tested it with other numbers …it seems this method does not work

A byte is interpreted as two’s complement per default.
As the comments say, you have to interpret bytes in an unsigned way.

okay, i see, thanks