public byte[] evaluate(Text s) {
    if (s == null) {
      return null;
    }

    // append a leading 0 if needed
    String str;
    if (s.getLength() % 2 == 1) {
      str = "0" + s.toString();
    } else {
      str = s.toString();
    }

    byte[] result = new byte[str.length() / 2];
    for (int i = 0; i < str.length(); i += 2) {
      try {
        result[i / 2] = ((byte) Integer.parseInt(str.substring(i, i + 2), 16));
      } catch (NumberFormatException e) {
        // invalid character present, return null
        return null;
      }
    }

    return result;
  }
Convert every two hex digits in s into.
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFUnhex.java