1. byte数组转int32(大端)
/**
* 数组BE转int
*
* @param bytes 数组大端BE
* @return int
*/
private int byteBE2Int(byte[] bytes) {
int addr;
if(bytes.length==1){
addr = bytes[0] & 0xFF;
}else{
addr = bytes[0] & 0xFF;
addr = (addr << 8) | (bytes[1] & 0xff) ;
addr = (addr << 8) | (bytes[2] & 0xff) ;
addr = (addr << 8) | (bytes[3] & 0xff) ;
}
return addr;
}
2. byte数组转Float(大端)
/**
* 数组BE转float
*
* @param bytes 数组大端BE
* @return float
*/
private float byteBE2Float(byte[] bytes) {
int l;
l = bytes[0];
l &= 0xff;
l |= ((long) bytes[1] << 8);
l &= 0xffff;
l |= ((long) bytes[2] << 16);
l &= 0xffffff;
l |= ((long) bytes[3] << 24);
return Float.intBitsToFloat(l);
}