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

How to use hex and octal numbers in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
NIRAJ BILGE

New User


Joined: 05 Aug 2006
Posts: 11

PostPosted: Wed Aug 16, 2006 12:46 am
Reply with quote

can anyone tell me, how to use hex and octal numbers in cobol.
i mean how to initialize them.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Aug 16, 2006 2:32 am
Reply with quote

Can you give an example of what you expect? What the results should be?

Dave
Back to top
View user's profile Send private message
NIRAJ BILGE

New User


Joined: 05 Aug 2006
Posts: 11

PostPosted: Fri Aug 18, 2006 10:37 am
Reply with quote

yes david
i just want to enter no. in respective no system
and will get display in the same.
i am writing appl. pgm for scientific calculator.
Back to top
View user's profile Send private message
Sridevi_C

Active User


Joined: 22 Sep 2005
Posts: 104
Location: Concord, New Hampshire, USA.

PostPosted: Fri Aug 18, 2006 10:20 pm
Reply with quote

COBOL is for business data and NOT for scientific stuff. "Octals" is still an alien to traditional COBOL.

Thanks.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Aug 19, 2006 4:14 am
Reply with quote

Code:

WORKING-STORAGE SECTION.                               
                                                       
01  WS-DEC-NUM              PIC X(10).                 
01  WS-HEX-NUM              PIC X(10).                 
01  WS-OCT-NUM              PIC X(10).                 
                                                       
01  WS-WORK1                PIC 9(10)   COMP-3.         
01  WS-WORK2                PIC 9(10)   COMP-3.         
01  WS-LEN1                 PIC 9(10)   COMP-3.         
                                                       
01  WS-CONV.                                           
    05  WS-CONST            PIC X(16)   VALUE           
        '0123456789ABCDEF'.                             
    05  WS-DIG REDEFINES WS-CONST                       
                            OCCURS 16 TIMES             
                            PIC X.                     
01  WS-SUB1                 PIC S9(3)   COMP-3. 

PROCEDURE DIVISION.                               
                                                 
PROGRAM-START.                                   
                                                 
    MOVE 0015288453      TO WS-DEC-NUM.           
    PERFORM C1000-DEC-HEX                         
        THRU C1000-EXIT.                         
    DISPLAY 'DEC NUMBER = ' WS-DEC-NUM           
           ' HEX NUMBER = ' WS-HEX-NUM.           
                                                 
    PERFORM C2000-DEC-OCT                         
        THRU C2000-EXIT.                         
    DISPLAY 'DEC NUMBER = ' WS-DEC-NUM           
           ' OCT NUMBER = ' WS-OCT-NUM.           
                                                 
    GOBACK.                                       
C1000-DEC-HEX.                                                   
    MOVE LENGTH OF WS-HEX-NUM TO WS-LEN1.                       
    MOVE WS-LEN1 TO WS-SUB1                                     
    MOVE WS-DEC-NUM  TO WS-WORK1.                               
    PERFORM                                                     
      VARYING WS-SUB1 FROM WS-LEN1 BY -1                         
      UNTIL WS-SUB1 < 1                                         
        DIVIDE WS-WORK1 BY 16 GIVING WS-WORK1 REMAINDER WS-WORK2
        MOVE WS-DIG(WS-WORK2 + 1) TO WS-HEX-NUM(WS-SUB1:1)       
    END-PERFORM.                                                 
C1000-EXIT.                                                     
    EXIT.                                                       
C2000-DEC-OCT.                                                 
    MOVE LENGTH OF WS-OCT-NUM TO WS-LEN1.                     
    MOVE WS-LEN1 TO WS-SUB1                                   
    MOVE WS-DEC-NUM  TO WS-WORK1.                             
    PERFORM                                                   
      VARYING WS-SUB1 FROM WS-LEN1 BY -1                       
      UNTIL WS-SUB1 < 1                                       
        DIVIDE WS-WORK1 BY 8 GIVING WS-WORK1 REMAINDER WS-WORK2
        MOVE WS-DIG(WS-WORK2 + 1) TO WS-OCT-NUM(WS-SUB1:1)     
    END-PERFORM.                                               
C2000-EXIT.                                                   
    EXIT.                                                     


Results of above code

Code:

DEC NUMBER = 0015288453 HEX NUMBER = 0000E94885       
DEC NUMBER = 0015288453 OCT NUMBER = 0072244205       


If you look at the code you will see that it can be condenced. I'll leave this up to you. If you have a problem convering from hex or oct to dec let me know.

Dave
Back to top
View user's profile Send private message
Sridevi_C

Active User


Joined: 22 Sep 2005
Posts: 104
Location: Concord, New Hampshire, USA.

PostPosted: Mon Aug 21, 2006 8:16 pm
Reply with quote

Thank you Dave. Good info.
Back to top
View user's profile Send private message
NIRAJ BILGE

New User


Joined: 05 Aug 2006
Posts: 11

PostPosted: Wed Aug 30, 2006 11:30 am
Reply with quote

thanks david.
thank u very much icon_biggrin.gif
Back to top
View user's profile Send private message
Sarva_bubli

New User


Joined: 09 Aug 2006
Posts: 37
Location: Pune, India

PostPosted: Wed Aug 30, 2006 12:04 pm
Reply with quote

Thanks Dave, It is a good info..

Regds,
Saravanan V.S
Pune,
India
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top