|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Convert a Charachter String to Bytes |
« View previous topic :: View next topic » |
Author |
Message
|
jigjim |
Posted: Thu Aug 25, 2005 12:03 pm Post subject: Convert a Charachter String to Bytes |
|
|
Apprentice
Joined: 30 Mar 2004 Posts: 41
|
Hi,
We put Fixed String format messages on the MQ Q using MQ Client and Java.
The messages are first retrieved from Mainframe and then reformatted to be put on the Q.
One of the requirements is that part of the message is Binary. So we represent that as a Charachter String (0123456789) max 10 chars.
When we put this on the MQ Q we have to convert it to a FIXED BIN number of 4 byte length
I tried this:
Code: |
msg.writeInt(getIntTransNo(xml.substring(26,36)));
public int getIntTransNo(String s) {
int a = 0;
try {
a = Integer.parseInt(s);
}
catch (Exception e){
e.printStackTrace();
}
return a;
}
|
The problem with this is Java's Signed representation. I was able to keep the Fixed String format correctly using a int but the Signed int in Java changed the value.
e.g ... the String was "0001933385", int value was 1933384 but Main fram got it as 1908936.
Does somebody know how to conevrt a 10 charachter numeric String to a 4 byte numerical value.
Thanks
Jigs |
|
Back to top |
|
 |
jigjim |
Posted: Thu Aug 25, 2005 12:05 pm Post subject: |
|
|
Apprentice
Joined: 30 Mar 2004 Posts: 41
|
sorry the charchter string was "0001933384" and not "0001933385". A small typo |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 25, 2005 12:30 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
|
Back to top |
|
 |
jigjim |
Posted: Fri Aug 26, 2005 5:31 am Post subject: |
|
|
Apprentice
Joined: 30 Mar 2004 Posts: 41
|
Can you provide links/more details on Unit.
My problem is to convert a Charachter String to a 4 byte (unsigned int, binary value) .. anything more then 4 bytes and the fixed string format gets violated.
Thanks
Jigs |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Aug 26, 2005 11:23 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You could try something like
Code: |
int myint = Integer.valueOf("123456789");
String hexval = Integer.toHexString(myint); |
Now with the hexval you can code each byte.
Remember to count 4 2 char pairs
use Integer.decode("0x"+ "ff")
REMEMBER the result is entirely garbled if you switch platform and send the message as text message. If you send the message as byte message you will either have to write a channel exit or do the ASCII/EBCDIC conversion in the app.
Enjoy  |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|