Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Decode hex format data

Hi,
Anyone know how to decode the hex format to unicode string?
regards,
Ommie
Labels (2)
15 Replies
janhess
Creator II
Creator II

You could probably use the Talend dataoperation functions XTD and CHAR.
Anonymous
Not applicable
Author

Is that a component? I couldn't find it.
janhess
Creator II
Creator II

No they are functions.
Or you could create a function like this that I found on the web. http://stackoverflow.com/questions/4785654/covert-a-string-of-hex-into-ascii-in-java
public static void main(String[] args) {
String hex = "75546f7272656e745c436f6d706c657465645c6e667375635f6f73745f62795f6d757374616e675c50656e64756c756d2d392c303030204d696c65732e6d7033006d7033006d7033004472756d202620426173730050656e64756c756d00496e2053696c69636f00496e2053696c69636f2a3b2a0050656e64756c756d0050656e64756c756d496e2053696c69636f303038004472756d2026204261737350656e64756c756d496e2053696c69636f30303800392c303030204d696c6573203c4d757374616e673e50656e64756c756d496e2053696c69636f3030380050656e64756c756d50656e64756c756d496e2053696c69636f303038004d50330000";
StringBuilder output = new StringBuilder();
for (int i = 0; i < hex.length(); i+=2) {
String str = hex.substring(i, i+2);
output.append((char)Integer.parseInt(str, 16));
}
System.out.println(output);
}
Replace the string in the code for an input argument.
Anonymous
Not applicable
Author

She has built the ETL job to decode hex to ascii but the output after decoding was garbled. That's why she asked why that issue happen. Since Sabrina said that Talend was not supported for hex to be decoded into ascii, she asked again whether Talend was not supported hex to be decoded into all kind of format(ascii, ebcdic...etc) or only to ascii? I'm sure the data is mixture of text and number.

p/s: Sabrina, do you have any idea on this?

Rgds,
Kal
Anonymous
Not applicable
Author

Hi,
There is no talend component you can use for your hex format data, and I think @janhess's suggestion is great.
Best regards
Sabrina
Anonymous
Not applicable
Author

This can be solved using user routine like what janhess suggested.
Create a routine name HexToString:
package routines;
public class HexToString {
public static String HexToASCII(String hex){
if(hex.length()%2 != 0){
System.err.println("requires EVEN number of chars");
return null;
}
StringBuilder sb = new StringBuilder();
//Convert Hex 0232343536AB into two characters stream.
for( int i=0; i<hex.length()-1; i+=2 ){
/*
* Grab the hex in pairs
*/
String output = hex.substring(i, (i + 2));
/*
* Convert Hex to Decimal
*/
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
}
return sb.toString();
}
}

You can get the code at http://jovialjava.blogspot.com/2010/05/hex-to-ascii-conversion-in-java.html
At tMap put:
routines.HexToString.HexToASCII(row1.ColumnA)
Regards,
Rozie