int --> byte[]
方式一
ByteBuffer.allocate(4).putInt(yourInt).array();
方式二
public static byte[] intToByteArray(int a)
{
byte[] ret = new byte[4];
ret[3] = (byte) (a & 0xFF);
ret[2] = (byte) ((a >> 8) & 0xFF);
ret[1] = (byte) ((a >> 16) & 0xFF);
ret[0] = (byte) ((a >> 24) & 0xFF);
return ret;
}
byte[] -->int
方式一
byte[] arr = new byte[] { 0, 0, 1, 100 };
ByteBuffer.wrap(arr).getInt()
方式二
byte[] b = new byte[] { 0, 0, 0, 100 };
int a = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];