Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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();
}
}