One Star

Decode hex format data

Hi,
Anyone know how to decode the hex format to unicode string?
regards,
Ommie
15 REPLIES
Moderator

Re: Decode hex format data

Hi,
Can you take a look at the tChangeFileEncode component? It is used to change the file encode, please try and let me know if it fixes your need.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Decode hex format data

Hi Sabrina,
Yes, but what type of encoding i should select if i want to encoding to string?
Regards,
Ommie
Moderator

Re: Decode hex format data

Hi,
If your input is hex format the hexadecimal ASCII data which cannot be supported by Talend. So far, we only support Octal ASCII.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Decode hex format data

Hi Sabrina,
Did you mean Talend does not support hexadecimal converter to ascii only???or to any format hexa cannot be decoded by Talend?

Regards,
Ommie
Moderator

Re: Decode hex format data

Hi,
We don't support to decode hexadecimal ASCII data in talend. If we read the hexadecimal ASCII data using talend, it might be garbled .
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Decode hex format data

We need to know what you want to convert the hex to. Is it base64 encoded or ebcdic or assci? Is it just text or a mixture of text and numbers?
One Star

Re: Decode hex format data

Hi,
From my understanding of Omie's requirement, she have data set that has been encoded as hex format. What she wants to do is to decoded it to ASCII so that she able to read the data.
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.
Rgds,
Kal
One Star

Re: Decode hex format data

If we don't know what sort of hex it is we can't decode it. If it's hex from ascii that's different from hex from ebcdic and is a problem if there's not a schema to identify where number fields start and stop.
One Star

Re: Decode hex format data

Hi Janhess,
I believe it is hex from ascii. That's why we need to decode it to ascii. We tried to used the data and convert it via online converter and it is worked. I really don't get what do you mean by field start and stop. its only one field and contained of a lot of row data that has been encoded to hex.
rgds,
Kal
One Star

Re: Decode hex format data

You could probably use the Talend dataoperation functions XTD and CHAR.
One Star

Re: Decode hex format data

Is that a component? I couldn't find it.
One Star

Re: Decode hex format data

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.
One Star

Re: Decode hex format data

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
Moderator

Re: Decode hex format data

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
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Decode hex format data

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