code: private static int toDigit(final char ch, final int index) {
          final int digit = Character.digit(ch, 16);
          if (digit == -1) {
              throw new RuntimeException("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
  
  @author Apache Software Foundation
  @see org.apache.commons.codec.binary.Hex