code: public static byte hexToByte(char hex) {
      if ('0' <= hex && hex <= '9') {
        return (byte) (hex - '0');
      } else if ('A' <= hex && hex <= 'F') {
        return (byte) (10 + hex - 'A');
      } else if ('a' <= hex && hex <= 'f') {
        return (byte) (10 + hex - 'a');
      } else {
        throw new IllegalArgumentException(String.format("'%c' is not a hexadecimal digit.", hex));
      }
    }
docs: Converts a hexadecimal digit to a byte.
  @param hex The hexadecimal digit.
  @return The byte value corresponding to <code>hex</code>.