int getInt ( byte [ ] b , int num ) { int base = 1 ; int i ; int word = 0 ; int bv [ ] = new int [ num ] ; for ( i = 0 ; i < num ; i ++ ) { bv [ i ] = convertunsignedByte2Short ( b [ i ] ) ; } if ( bv [ 0 ] > 127 ) { bv [ 0 ] -= 128 ; base = - 1 ; } /* ** Calculate the integer value of the byte sequence */ for ( i = num - 1 ; i >= 0 ; i -- ) { word += base * bv [ i ] ; base *= 256 ; } return word ; }
get signed integer from bytes