Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
sid_ibm

New User

Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

 Posted: Thu Mar 25, 2010 1:08 pm    Post subject: conversion from hexadecimal to binary using natural 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

enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Thu Mar 25, 2010 1:42 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura this is a help forum, not a ... do it for me / give me the code to
sid_ibm

New User

Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

 Posted: Thu Mar 25, 2010 1:48 pm    Post subject: SORRY 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
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

Posted: Thu Mar 25, 2010 2:11 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura

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
sid_ibm

New User

Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

 Posted: Thu Mar 25, 2010 2:35 pm    Post subject: Thanks I tried to excute my code but in display only zeros are coming.Please correct me if I am wrong

New User

Joined: 15 Jun 2006
Posts: 26

Posted: Fri Mar 26, 2010 6:08 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura

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

New User

Joined: 15 Jun 2006
Posts: 26

Posted: Mon Mar 29, 2010 5:54 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura

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
Ralph Zbrog

New User

Joined: 21 Nov 2009
Posts: 58
Location: California

Posted: Tue Mar 30, 2010 7:38 pm    Post subject: Reply to: conversion from hexadecimal to binary using natura

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
sid_ibm

New User

Joined: 25 Mar 2010
Posts: 4
Location: Bangalore

 Posted: Thu Apr 01, 2010 9:56 am    Post subject: Reply to: conversion from hexadecimal to binary using natura Hi All Thanks to all .I really thankful.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Conversion of DLI update Jobs as BMP ... Gopinath Shanmugam IMS DB/DC 3 Wed Dec 20, 2017 12:02 pm Conversion of UTF-8 to EBCDIC muralikrishnan_new COBOL Programming 1 Tue Nov 21, 2017 5:33 pm Mainframe Blocks to Tracks conversion upendrasri JCL & VSAM 1 Sat Nov 18, 2017 10:52 am Binary to display characters Roy Ware SYNCSORT 3 Tue Sep 19, 2017 8:46 pm Reg:Displaying the particular month o... bhavana yalavarthi All Other Mainframe Topics 4 Sat Jul 08, 2017 8:13 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us