IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

conversion from hexadecimal to binary using natural


IBM Mainframe Forums -> Java & MQSeries
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sid_ibm

New User


Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

PostPosted: Thu Mar 25, 2010 1:08 pm
Reply with quote

Hi Please let me know the code for below question

1) Natural program which will convert a Hexadecimal number into Binary
2)Write a Natural module which will take 20 numbers as input and then it will display them in a sorted way
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Thu Mar 25, 2010 1:42 pm
Reply with quote

this is a help forum, not a ... do it for me / give me the code to
Back to top
View user's profile Send private message
sid_ibm

New User


Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

PostPosted: Thu Mar 25, 2010 1:48 pm
Reply with quote

Hi sorry I didnt mean like that,kindly let me know please.I am giving my code below but I am not getting the binary result:
0010 DEFINE DATA LOCAL
0020 01 #BINARY10(B10)
0030 01 #T1 (B10)
0040 01 #T2 (B10)
0050 01 #T3 (B10)
0060 END-DEFINE
0070 MOVE ALL H'ABCD' TO #BINARY10
0080 DECIDE FOR EVERY CONDITION
0090 WHEN #BINARY10 = 'A'
0100 MOVE '1010' TO #T2
0110 WRITE #T2
0120 WHEN #BINARY10 = 'B'
0130 MOVE '1011' TO #T3
0140 WRITE #T3
0150 WHEN NONE
0160 IGNORE
0170 END-DECIDE
0180 write #t1 #t2 #t3
0190 END
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Thu Mar 25, 2010 2:11 pm
Reply with quote

apart the NATURAL considerations remember that HEX notation is a shorthand representation of a binary entity, the bits are just the same

Code:
x'01' == b'00000001'
...
x'09' == b'00001001'
x'0A' == b'00001010'
...
x'0F' == b'00001111'


just a different way of displaying the same thing
Back to top
View user's profile Send private message
sid_ibm

New User


Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

PostPosted: Thu Mar 25, 2010 2:35 pm
Reply with quote

I tried to excute my code but in display only zeros are coming.Please correct me if I am wrong
Back to top
View user's profile Send private message
atulbagewadikar

New User


Joined: 15 Jun 2006
Posts: 26

PostPosted: Fri Mar 26, 2010 6:08 pm
Reply with quote

Hi Sid,

What Enrico said is correct. However, if you still want to achieve it programmatically I have done a micky mouse one for two digit hex value. The program can be further modified for less coding but still this may help you.

Code:
DEFINE DATA LOCAL                                                       
1 #VAR1 (A2)                                                           
1 REDEFINE #VAR1                                                       
  2 #1ST-CH (A1)                                                       
  2 #2ND-CH (A1)                                                       
1 #VAR2 (A8)                                                           
1 REDEFINE #VAR2                                                       
  2 #1ST-BIN (A4)                                                       
  2 #2ND-BIN (A4)                                                       
1 #HEX-CONST (A1/16) CONST <'0','1','2','3','4','5','6','7','8','9'     
  ,                           'A','B','C','D','E','F'>                 
1 #BIN-CONST (A4/16) CONST <'0000','0001','0010','0011','0100','0101'   
  , '0110','0111','1000','1001','1010','1011','1100','1101','1110','1111'>
1 #I (I2)                                                               
END-DEFINE                                                             
INPUT 'Please enter a HEX no:' #VAR1                                   
FOR #I 1 TO 16                                                         
  IF #1ST-CH = #HEX-CONST(#I)                                           
    MOVE #BIN-CONST(#I) TO #1ST-BIN                                     
  END-IF                                                               
END-FOR                                   
RESET #I                                 
FOR #I 1 TO 16                           
  IF #2ND-CH = #HEX-CONST(#I)             
    MOVE #BIN-CONST(#I) TO #2ND-BIN       
  END-IF                                 
END-FOR                                   
WRITE 'The HEX no entered = ' #VAR1 //   
WRITE 'The equivalent BINARY no = ' #VAR2
END                                       


Output

Code:
Page      1                                                  26/03/10  12:33:57
                                                                               
The HEX no entered =  AB                                                       
                                                                               
                                                                               
The equivalent BINARY no =  10101011                                           
Back to top
View user's profile Send private message
atulbagewadikar

New User


Joined: 15 Jun 2006
Posts: 26

PostPosted: Mon Mar 29, 2010 5:54 pm
Reply with quote

Sid,

For your 2nd query (sorting nos) there are many ways to do it and sorting methods available. I am posting a micky mouse code (done for 5 nos). As I said there are other optimum ways too, please try to find them.

Code:
0010 DEFINE DATA LOCAL                         
0020 1 #VAR1 (N2/5)                             
0030 1 #VAR2 (N2/5)                             
0040 1 #I (I2)                                 
0050 1 #J (I2)                                 
0060 1 #TEMP (N2)                               
0070 1 #COUNTER (I2)                           
0080 END-DEFINE                                 
0090 FOR #I 1 TO 5                             
0100   INPUT 'Input a 2 digit no: ' #VAR1(#I)   
0110   MOVE #VAR1(#I) TO #VAR2(#I)             
0120 END-FOR                                   
0130 REPEAT UNTIL #COUNTER >  5                 
0140   RESET #I #J                             
0150   FR1.                                     
0160   FOR #I 1 TO 5                           
0170     IF #I = 5                             
0180       ESCAPE BOTTOM(FR1.)                 
0190     ELSE                                   
0200       #J := #I+1                           
0210       IF #VAR2(#I) GT #VAR2(#J)                           
0220         MOVE #VAR2(#I) TO #TEMP                           
0230         MOVE #VAR2(#J) TO #VAR2(#I)                       
0240         MOVE #TEMP TO #VAR2(#J)                           
0250       END-IF                                             
0260     END-IF                                               
0270   END-FOR                                                 
0280   #COUNTER := #COUNTER+1                                 
0290 END-REPEAT                                               
0300 FOR #I 1 TO 5                                             
0310   DISPLAY 'Nos Enterred ' #VAR1(#I) 'Sorted Nos' #VAR2(#I)
0320 END-FOR                                                   
0330 END                                                       


Output

Code:
Page      1                                                  29/03/10 
                                                                               
Nos Enterred  Sorted Nos                                                       
------------- ----------                                                       
                                                                               
 23             7                                                             
 56            14                                                             
 14            23                                                             
  7            56                                                             
 57            57                                                             
Back to top
View user's profile Send private message
Ralph Zbrog

New User


Joined: 21 Nov 2009
Posts: 58
Location: California

PostPosted: Tue Mar 30, 2010 7:38 pm
Reply with quote

Alpha/hex to binary conversion requires a single statement. To demonstrate that it works for all hex codes, I've used an A16 source field and a B8 target:
Code:
DEFINE DATA LOCAL
1 #ALPHA (A16) INIT <'0123456789ABCDEF'>
1 #BIN (B8)
END-DEFINE
MOVE EDITED #ALPHA TO #BIN (EM=H(8))
DISPLAY #ALPHA #BIN
END
Code:
Page     1                                                   03/30/10  07:06:29

     #ALPHA            #BIN
---------------- ----------------

0123456789ABCDEF 0123456789ABCDEF
Back to top
View user's profile Send private message
sid_ibm

New User


Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

PostPosted: Thu Apr 01, 2010 9:56 am
Reply with quote

Hi All

Thanks to all .I really thankful.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Java & MQSeries

 


Similar Topics
Topic Forum Replies
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts SMF Record Date conversion failing CLIST & REXX 1
No new posts Assembler class assignment: stuck on ... PL/I & Assembler 12
Search our Forums:

Back to Top