I am trying to get data from one application and send that to another(mainframe) after processing the data.

Lets assume I am getting data as "This is from another application", processed the same and processing status as "This data is processed". Final message should be combination of both using encoding(Cp1047) to mainframe application to read the same as  

> 
> **0024**This is from another application**001A**This data is processed
> 
> 
> 

decimal value of 0024 is 36 (message length + 4 which is hexa value length)  

decimal value of 001A is 26 (processed message length + 4)  

My application runs on Java8 and uses websphere MQ. I need to send data to application which receives data from Mainframe MQ. Remote queue in WebSphere MQ puts messge to Local Queue of Mainframe MQ. My code as below to convert data and encode using Cp1047,

```
String incomingData = "This is from another application";
String processingData = "This data is processed" 
public String outGoingData(String incomingData, String processingData) {  
  StringBuilder strBuilder = new StringBuilder();
  return stringbuilder.append(new String(convertToEbcidie(incomingData, "Cp1047")))
  .append(incomingData)
  .append(new String(convertToEbcidie(processingData, "Cp1047")))
  .append(processing data).toString(); //playing this string to queue
}
private byte[] convertToEbcidic(String s) {
  String hexStr = StringUtils.leftPad(s.length+4, 8, "0");
  byte[] byteAry = new byte[hexStr.length()/2];
  for (int i = 0; i < hexStr.length(); i+=2) {
    byteAry[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                   + Character.digit(s.charAt(i+1), 16)); 
  }  return byteAry;
}

```

Receiver application(mainframe) decide which is original message and processing status based hexavalue which is 4 characters. **They are able to read most of the messages but not all. for ex, hexa value of length 805 is 325, but in mainframe mq entry is as 315. They are not able to process since the length mismatches.**

> 
> ANOTHER SAMPLE DATA :- 
>  **OO25**THIS IS ORIGINAL DATA FROM SOURCE**001A**PROCESSED SUCCESSFULLY
> 
> 
> 

0025 is hexval of org msg length(33) + 4 and 001A is hexval of processed msg length (22) + 4. Here 4 is the length of hexa decimal value.  
 Am I missing any logic to convert to ebcidic?