public static int unsignedBinarySearch(byte[] a, int fromIndex, int toIndex, byte key) {
    int unsignedKey = key & 0xff;
    int low = fromIndex;
    int high = toIndex - 1;

    while (low <= high) {
      int mid = low + ((high - low) >> 1);
      int midVal = a[mid] & 0xff;

      if (midVal < unsignedKey) {
        low = mid + 1;
      } else if (midVal > unsignedKey) {
        high = mid - 1;
      } else {
        return mid; // key found
      }
    }
    return -(low + 1); // key not found.
  }
Search sorted array "a" for byte "key". I can't remember if I wrote this or copied it from
somewhere. (mcorgan)
@param a         Array to search. Entries must be sorted and unique.
@param fromIndex First index inclusive of "a" to include in the search.
@param toIndex   Last index exclusive of "a" to include in the search.
@param key       The byte to search for.
@return The index of key if found. If not found, return -(index + 1), where negative indicates
        "not found" and the "index + 1" handles the "-0" case.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java