public static byte[] hexStringToByte(String hex) {
    byte[] bts = new byte[hex.length() / 2];
    for (int i = 0; i < bts.length; i++) {
      bts[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
    }
    return bts;
  }
Given a hexstring this will return the byte array corresponding to the
string
@param hex the hex String array
@return a byte array that is a hex string representation of the given
        string. The size of the byte array is therefore hex.length/2
common/src/java/org/apache/hive/common/util/HiveStringUtils.java