code: protected static int toDigit(char ch, int index) throws DecoderException {
          int digit = Character.digit(ch, 16);
          if (digit == -1) {
              throw new DecoderException("Illegal hexadecimal charcter " + ch + " at index " + index);
          }
          return digit;
      }
docs: Converts a hexadecimal character to an integer.
  
  @param ch A character to convert to an integer digit
  @param index The index of the character in the source
  @return An integer
  @throws DecoderException Thrown if ch is an illegal hex character