/**
* 将byte类型数据转为int型
*/
public static int bytesToInt(byte[] bytes) {
int mask = 0xff, temp = 0, result = 0;
for (int i = 0; i < 4; i++) {
result <<= 8;
temp = bytes[i] & mask;
result |= temp;
}
return result;
}
/**
* 将int类型数据转为byte型
*/
public static byte[] intToBytes(int num){
byte[] result = new byte[4];
for(int i=0;i<4;i++){
result[i] = (byte)(num>>>(24-i*8));
}
return result;
}
byte int 转换
最新推荐文章于 2024-02-21 14:14:10 发布