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

how to convert and use 1 bit hex-number using COBOL


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

New User


Joined: 29 Jun 2021
Posts: 16
Location: India

PostPosted: Wed Sep 22, 2021 9:22 pm
Reply with quote

how to convert a 1 bit hex number to decimal form, or at least use it for some mathematical operation.

the problem is that this 1 bit hex number can be viewed only in hex form that too after turning hex on in the file.

the maximum hex value that will be present in 1 bit is FF which is 255 in decimal.

please guide.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 418
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Wed Sep 22, 2021 9:33 pm
Reply with quote

I believe that is a 1 byte number in packed decimal.

X’1F’. F may be interpreted as unsigned and may be interpreted as positive.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Wed Sep 22, 2021 9:37 pm
Reply with quote

As always:

What is your input, desired output. If you follow the forum you should know how it works. Attachments in general will not be read.
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 16
Location: India

PostPosted: Wed Sep 22, 2021 9:49 pm
Reply with quote

hey dneufarth, this 1F is considered as 31 only.

the thing is i am not able to convert this 1F to 31.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 418
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Wed Sep 22, 2021 10:55 pm
Reply with quote

Try reading this

ibmmainframes.com/about41628.html
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 16
Location: India

PostPosted: Thu Sep 23, 2021 12:09 am
Reply with quote

dneufarth wrote:
Try reading this

ibmmainframes.com/about41628.html


This approach wont work in my case as the approach you suggested is the one using JCLs.

In my case at certain intervals (not fixed) i am supposed to read this hex values.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 418
Location: Inside the SPEW (Southwest Ohio, USA)

PostPosted: Thu Sep 23, 2021 12:09 am
Reply with quote

Please move to COBOL forum.
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 16
Location: India

PostPosted: Thu Sep 23, 2021 12:10 am
Reply with quote

[quote="anonguy456"]
dneufarth wrote:
Try reading this

ibmmainframes.com/about41628.html


This approach wont work in my case as the approach you suggested is the one using JCLs.

In my case at certain intervals (not fixed) i am supposed to read this hex values from an input file.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Thu Sep 23, 2021 1:39 am
Reply with quote

anonguy456 wrote:

This approach wont work in my case as the approach you suggested is the one using JCLs.

Please, learn carefully the difference between JCL, COBOL, and system utilities.

Before that, it does not make sense to discuss ANY issue.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 23, 2021 2:53 am
Reply with quote

The first thing to know is that the term "bit" refers to a single 0/1 value -- there are 8 bits to a byte, and a byte is what you are calling a bit. Bit is short for binary digit. So terminology is your first, and a very major, issue.

Second, it is EASY to use hex bytes for arithmetic in COBOL. Define a COBOL group variable with 2 1-byte variables in the group. REDEFINE the group to be a half-word binary value (COMP-5 although COMP will also work; COMP-1, COMP-2, COMP-3 are not suitable for this). Move LOW-VALUES to your group variable. Move your hex variable to the second byte of the group variable. Use the REDEFINE variable as a numeric value for whatever you want to do with it.
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 16
Location: India

PostPosted: Sat Sep 25, 2021 8:58 am
Reply with quote

Robert Sample wrote:
The first thing to know is that the term "bit" refers to a single 0/1 value -- there are 8 bits to a byte, and a byte is what you are calling a bit. Bit is short for binary digit. So terminology is your first, and a very major, issue.

Second, it is EASY to use hex bytes for arithmetic in COBOL. Define a COBOL group variable with 2 1-byte variables in the group. REDEFINE the group to be a half-word binary value (COMP-5 although COMP will also work; COMP-1, COMP-2, COMP-3 are not suitable for this). Move LOW-VALUES to your group variable. Move your hex variable to the second byte of the group variable. Use the REDEFINE variable as a numeric value for whatever you want to do with it.


Thank You Robert icon_smile.gif

Sample of code for reference:
Code:
01 WS-LENGTH.                                               
   02 WS-LENGTH1             PIC X(01).                     
   02 WS-LENGTH2             PIC X(01).                     
01 WS-CONVERTED-LENGTH REDEFINES WS-LENGTH PIC 9(02) COMP-5.
01 WS-TEMP                   PIC 9(03) VALUE 0.             
**************************************************         
PROCEDURE DIVISION.                                         
MAIN-PARA.                                                 
    MOVE LOW-VALUES TO WS-LENGTH                           
    MOVE INPUT1-RECORD(171:1) TO WS-LENGTH2                 
    PERFORM WS-CONVERTED-LENGTH TIMES                       
       ADD 1 TO WS-TEMP                                     
    END-PERFORM                                             
    DISPLAY WS-TEMP         
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top