I have a method that converts int to byte[]
private static byte[] intToBytes(int i)
{
byte[] integerBs = new byte[MAX_INT_LEN];
integerBs[0] = (byte) ((i >>> 24) & 0xFF);
integerBs[1] = (byte) ((i >>> 16) & 0xFF);
integerBs[2] = (byte) ((i >>> 8) & 0xFF);
integerBs[3] = (byte) (i & 0xFF);
return integerBs;
}
Let's say I try to convert the integer 4 to bits:
byte[] lenBs = intToBytes(4);
int a=(int)lenBs[0];
System.out.println("result:"+a);
The value of MAX_INT_LENGTH is 4
I get result:0 for every int that I put as a parameter for the method.Please tell me where i went wrong.Thank you.