private static BigDecimal decodeSignificand(PositionedByteRange src, int e, boolean comp) {
    // TODO: can this be made faster?
    byte[] a = src.getBytes();
    final int start = src.getPosition(), offset = src.getOffset(), remaining = src.getRemaining();
    Order ord = comp ? DESCENDING : ASCENDING;
    BigDecimal m;
    StringBuilder sb = new StringBuilder();
    for (int i = 0;; i++) {
      if (i > remaining) {
        // we've exceeded this range's window
        src.setPosition(start);
        throw new IllegalArgumentException(
          "Read exceeds range before termination byte found. offset: " + offset + " position: "
            + (start + i));
      }
      // one byte -> 2 digits
      // base-100 digits are encoded as val * 2 + 1 except for the termination digit.
      int twoDigits = (ord.apply(a[offset + start + i]) & 0xff) / 2;
      sb.append(String.format("%02d", twoDigits));
      // detect termination digit
      // Besides, as we will normalise the return value at last,
      // we only need to decode at most MAX_PRECISION + 2 digits here.
      if ((ord.apply(a[offset + start + i]) & 1) == 0 || sb.length() > MAX_PRECISION + 1) {
        src.setPosition(start + i + 1);
        break;
      }
    }
    m = new BigDecimal(sb.toString());
    int stepsMoveLeft = sb.charAt(0) != '0' ? m.precision() : m.precision() + 1;
    stepsMoveLeft -= e * 2;

    return normalize(m.movePointLeft(stepsMoveLeft));
  }
Read significand digits from {@code src} according to the magnitude of {@code e}.
@param src  The source from which to read encoded digits.
@param e    The magnitude of the first digit read.
@param comp Treat encoded bytes as compliments when {@code comp} is true.
@return The decoded value.
@throws IllegalArgumentException when read exceeds the remaining length of {@code src}.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java