View previous topic :: View next topic
|
Author |
Message |
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
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 |
|
 |
dneufarth
Active User

Joined: 27 Apr 2005 Posts: 415 Location: Inside the SPEW (Southwest Ohio, USA)
|
|
|
|
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 |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1138 Location: Bamberg, Germany
|
|
|
|
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 |
|
 |
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
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 |
|
 |
dneufarth
Active User

Joined: 27 Apr 2005 Posts: 415 Location: Inside the SPEW (Southwest Ohio, USA)
|
|
Back to top |
|
 |
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
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 |
|
 |
dneufarth
Active User

Joined: 27 Apr 2005 Posts: 415 Location: Inside the SPEW (Southwest Ohio, USA)
|
|
|
|
Please move to COBOL forum. |
|
Back to top |
|
 |
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
[quote="anonguy456"]
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 |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 1884 Location: USA
|
|
|
|
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 |
|
 |
Robert Sample
Global Moderator

Joined: 06 Jun 2008 Posts: 8693 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
 |
anonguy456
New User
Joined: 29 Jun 2021 Posts: 16 Location: India
|
|
|
|
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
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 |
|
 |
|