View previous topic :: View next topic
|
Author |
Message |
krrp
New User
Joined: 23 Oct 2015 Posts: 12 Location: canada
|
|
|
|
Hi How to convert char to hex
my requirement
example
Input
Pic x(10) value '99999' (Leading spaces)
Output in Hex leading spaces to be converted to X'AA'
AAAA99
AAA999
I can move it to a packed and remove the sign nibble, but how to handle the leading spaces as AAAAA?
Thanks,
krrp |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I think you need to explain a LOT more before you start getting answers that make sense. Questions that popped up as I was reading your post:
1. PIC X(10) VALUE '99999' will have trailing spaces -- not leading spaces. How do you get leading spaces into it?
2. PIC X(10) VALUE '99999' will not have a hex value of 99 or 999 -- the precise hex value will be F9F9F9F9F94040404040. So why the incorrect hex data?
3. Your variable is 10 bytes but your examples only have 6 (or 3 if those are supposed to be hex characters) bytes -- why?
4. You mention moving the data to "a packed" (presumably a packed decimal variable but who knows the way you wrote your post?) -- what does packed decimal have to do with anything?
5. If you are wanting a packed decimal variable at some point, X'AA' is not valid packed decimal data so you're going to have problems. How are you going to deal with them?
6. Why not use reference modification (or a REDEFINES of the 10-byte PIC X variable into 10 1-byte PIC X variables) and look at each byte? If the byte is a space, change it -- otherwise, stop the loop. |
|
Back to top |
|
|
krrp
New User
Joined: 23 Oct 2015 Posts: 12 Location: canada
|
|
|
|
Okay Robert...please see my requirement...I need the leading spaces as AA when converted to hex.
Code: |
******************************************************* Top of Data **
INPUT
01 WS-FLD1 PIC X(10).
01 WS-FLD2 PIC X(08).
OUTPUT
01 WS-OUT1 PIC X(05).
01 WS-OUT2 PIC X(04).
INPUT FILE
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
2345612345678
OUTPUT FILE (HEX FORMAT)
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
¡¡S î îÌ
AAA3513574444444444444444444444444444444444444444444444444444444444444
AA24624680000000000000000000000000000000000000000000000000000000000000
|
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Search the Mainframe COBOL forum for CHAR2HEX and you will find what you need.
You'll need to adapt the sample program to accommodate for a X'40' to be represented as a 4-Bit X'A'. The easiest way to do this is to issue an INSPECT CONVERTING SPACE TO 'A' and then proceed with the conversion loop.
HTH... |
|
Back to top |
|
|
krrp
New User
Joined: 23 Oct 2015 Posts: 12 Location: canada
|
|
|
|
Wow...Thanks Bill |
|
Back to top |
|
|
|