The following code is to convert an int to Bytes array.
I know the int i
is right shifted 24, 16, 8 times and ANDED with 0xFF but what I can't understand is why these numbers were used?
private static byte[] intToBytes(int i)
// split integer i into 4 byte array
{
// map the parts of the integer to a byte array
byte[] integerBs = new byte[4];
integerBs[0] = (byte) ((i >>> 24) & 0xFF);
integerBs[1] = (byte) ((i >>> 16) & 0xFF);
integerBs[2] = (byte) ((i >>> 8) & 0xFF);
integerBs[3] = (byte) (i & 0xFF);
// for (int j=0; j < integerBs.length; j++)
// System.out.println(" integerBs[ " + j + "]: " + integerBs[j]);
return integerBs;
} // end of intToBytes()