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 » WebSphere Message Broker (ACE) Support » Convert Hexa to Binary

Post new topic  Reply to topic
 Convert Hexa to Binary « View previous topic :: View next topic » 
Author Message
N
PostPosted: Tue Feb 19, 2008 12:53 am    Post subject: Convert Hexa to Binary Reply with quote

Acolyte

Joined: 21 Jul 2007
Posts: 64

Hi Guys,

Is this the ideal way to convert hexadecimal to binary?

CREATE PROCEDURE HexToBinary(IN X CHARACTER, OUT Y CHARACTER) BEGIN

-- HEX TO BINARY
IF X=0 THEN
SET Y = '0000';
ELSEIF X=1 THEN
SET Y = '0001';
ELSEIF X=2 THEN
SET Y = '0010';
ELSEIF X=3 THEN
SET Y = '0011';
..............................

ELSEIF X='F' THEN
SET Y = '1111';

END IF;
Back to top
View user's profile Send private message
mgk
PostPosted: Tue Feb 19, 2008 1:09 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Have you tries CASTing it to a BIT datatype?
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Feb 19, 2008 3:06 am    Post subject: Reply with quote

Grand High Poobah

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

Java has a very efficient converter see Integer.decode(string)

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
N
PostPosted: Tue Feb 19, 2008 5:41 pm    Post subject: Reply with quote

Acolyte

Joined: 21 Jul 2007
Posts: 64

Hi,

I'd tried BIT data type, however the outcome prefix with B'<binary>'.

Meanwhile, i tried not to use java in my ESQL.

Thanks.
Back to top
View user's profile Send private message
fschofer
PostPosted: Wed Feb 20, 2008 1:00 am    Post subject: Reply with quote

Knight

Joined: 02 Jul 2001
Posts: 524
Location: Mainz, Germany

Hi,

why not simply remove the B' at the beginning and the ' at the end ?

Greetings
Frank
Back to top
View user's profile Send private message Send e-mail
mgk
PostPosted: Wed Feb 20, 2008 2:58 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

You can try some ESQL like the following:

Code:
  DECLARE input CHAR 'F'; /* value = F */
  SET  input = '0x' || input; /* value = 0xF */
  DECLARE tmpInt1 INT CAST( input AS INT); /* value = 15 */
  DECLARE binStr BIT CAST( tmpInt1 AS BIT ); /*value = B'0000000000000000000000000000000000000000000000000000000000001111' */
  DECLARE output CHAR CAST( binStr AS CHAR); /*value = 'B'0000000000000000000000000000000000000000000000000000000000001111'' */
  SET output = TRIM( LEADING 'B' FROM output ); /*value = ''0000000000000000000000000000000000000000000000000000000000001111'' */
  SET output = TRIM( BOTH '''' FROM output ); /*value = '0000000000000000000000000000000000000000000000000000000000001111' */
  SET output = TRIM( LEADING '0' FROM output ); /*value = '1111' */


Regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
N
PostPosted: Wed Feb 20, 2008 11:37 pm    Post subject: Reply with quote

Acolyte

Joined: 21 Jul 2007
Posts: 64

HI,

Thanks for your snippet. Does this code cater for Z/OS EBCDIC and WIN32 ASCII?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Feb 21, 2008 2:28 pm    Post subject: Reply with quote

Grand High Poobah

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

N wrote:
HI,

Thanks for your snippet. Does this code cater for Z/OS EBCDIC and WIN32 ASCII?

Hex is hex and does not care as long as you keep it in a byte array.
Now if you are talking about CHAR (as in char representation of the hex value of the byte array) you'll have to use CAST to move from one CCSID to the other, or a GET with Translate.

Enjoy
_________________
MQ & Broker admin
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 » WebSphere Message Broker (ACE) Support » Convert Hexa to Binary
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.