ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Convert a Charachter String to Bytes

Post new topic  Reply to topic
 Convert a Charachter String to Bytes « View previous topic :: View next topic » 
Author Message
jigjim
PostPosted: Thu Aug 25, 2005 12:03 pm    Post subject: Convert a Charachter String to Bytes Reply with quote

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
View user's profile Send private message
jigjim
PostPosted: Thu Aug 25, 2005 12:05 pm    Post subject: Reply with quote

Apprentice

Joined: 30 Mar 2004
Posts: 41

sorry the charchter string was "0001933384" and not "0001933385". A small typo
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Aug 25, 2005 12:30 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

have you tried uint ?
Back to top
View user's profile Send private message Send e-mail
jigjim
PostPosted: Fri Aug 26, 2005 5:31 am    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Fri Aug 26, 2005 11:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Convert a Charachter String to Bytes
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.