Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
conversion from hexadecimal to binary using natural

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Java & MQSeries
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    Post subject: conversion from hexadecimal to binary using natural
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10326
Location: italy

PostPosted: Thu Mar 25, 2010 1:42 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura
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    Post subject: SORRY
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10326
Location: italy

PostPosted: Thu Mar 25, 2010 2:11 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura
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    Post subject: Thanks
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    Post subject: Reply to: conversion from hexadecimal to binary using natura
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    Post subject: Reply to: conversion from hexadecimal to binary using natura
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    Post subject: Reply to: conversion from hexadecimal to binary using natura
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    Post subject: Reply to: conversion from hexadecimal to binary using natura
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    IBMMAINFRAMES.com Support Forums -> Java & MQSeries All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Binary to display characters Roy Ware SYNCSORT 3 Tue Sep 19, 2017 8:46 pm
No new posts Reg:Displaying the particular month o... bhavana yalavarthi All Other Mainframe Topics 4 Sat Jul 08, 2017 8:13 pm
No new posts Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts resume binary ftp in z/os meykh2014 All Other Mainframe Topics 6 Sun Jan 22, 2017 10:01 am
This topic is locked: you cannot edit posts or make replies. Natural ADABAS Opening with CTS enikhilk Mainframe Jobs 0 Wed Nov 30, 2016 5:37 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us