public static int binarySearch ( byte [ ] a , int key ) { int low = 0 ; int high = a . length ; while ( low < high ) { int mid = ( low + high ) >>> 1 ; if ( mid % 4 != 0 ) { if ( high == a . length ) { mid = low ; } else { mid = high ; } } int midVal = getInt ( a , mid ) ; if ( midVal < key ) low = mid + 4 ; else if ( midVal > key ) high = mid - 4 ; else return mid ; // key found } if ( low == a . length ) { return low ; } return key > getInt ( a , low ) ? low + 4 : low ; }
Search for a big - endian 4 - byte integer in a array of bytes .