View previous topic :: View next topic
|
Author |
Message |
selvamsrinivasan85
New User

Joined: 09 Aug 2010 Posts: 33 Location: Chennai
|
|
|
|
Hi all,
I am receiving a 10 byte hex value (like X'808E640000') in a file. Corresponding layout has a variable, defined as X(5).
Now i am supposed to convert that hex value to a decimal value of 12 bytes (like 552144732160).
How can i achieve this?. Since its a 10 byte, unable to use COMP.
Throw some light on this. I will try at my end. |
|
Back to top |
|
 |
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
I don't know if there is a COBOL function for this, but it should be easy enough to write the code to multiply each hex-digit's value by the value of its position and then add them up. |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2159 Location: USA
|
|
Back to top |
|
 |
selvamsrinivasan85
New User

Joined: 09 Aug 2010 Posts: 33 Location: Chennai
|
|
|
|
Hi Phil,
Thanks for the suggestion. Will give a try on that.
Hi Sergeyken,
If I declare as 9(9) comp-5, it occupies 4 bytes only and the last bytes is getting displayed on next variable and if i declare 9(10), it occupies 8 bytes. It looks like COMP and COMP-5 doesn't have any difference here. |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2159 Location: USA
|
|
|
|
selvamsrinivasan85 wrote: |
Hi Phil,
Thanks for the suggestion. Will give a try on that.
Hi Sergeyken,
If I declare as 9(9) comp-5, it occupies 4 bytes only and the last bytes is getting displayed on next variable and if i declare 9(10), it occupies 8 bytes. It looks like COMP and COMP-5 doesn't have any difference here. |
You MUST declare your intermediate PIC 9(12) COMP-5 field (8 bytes), and populate its lower part with your initial X(5) - via REDEFINE, or any other trick. |
|
Back to top |
|
 |
jerryte
Active User

Joined: 29 Oct 2010 Posts: 205 Location: Toronto, ON, Canada
|
|
|
|
Is your input a 10 byte character string made of hexadecimal chars? If so then you might have to do this hard way ie. one char at a time. |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2159 Location: USA
|
|
|
|
jerryte wrote: |
Is your input a 10 byte character string made of hexadecimal chars? If so then you might have to do this hard way ie. one char at a time. |
The input is FIVE BYTES HEX DATA, as shown: X'808E640000'.
Please, read the post carefully. |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2159 Location: USA
|
|
|
|
sergeyken wrote: |
selvamsrinivasan85 wrote: |
Hi Phil,
Thanks for the suggestion. Will give a try on that.
Hi Sergeyken,
If I declare as 9(9) comp-5, it occupies 4 bytes only and the last bytes is getting displayed on next variable and if i declare 9(10), it occupies 8 bytes. It looks like COMP and COMP-5 doesn't have any difference here. |
You MUST declare your intermediate PIC 9(12) COMP-5 field (8 bytes), and populate its lower part with your initial X(5) - via REDEFINE, or any other trick. |
Code: |
01 INPUT-DATA PIC X(5) VALUE X'0123456789'.
01 RECALC-AREA.
05 LONG-BINARY PIC 9(12) COMP-5.
05 SPLIT-AREA REDEFINES LONG-BINARY.
10 FILLER PIC X(3).
10 HEX-COPY PIC X(5).
05 LONG-DEC-PACKED PIC 9(12) COMP-3.
05 LONG-DEC-CHAR PIC 9(12).
. . . . . . . . .
LONG-BINARY = 0
HEX-COPY = INPUT-DATA
LONG-DEC-PACKED = LONG-BINARY
LONG-DEC-CHAR = LONG-DEC-PACKED
. . . . . |
|
|
Back to top |
|
 |
|