Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conversion: Packed-Hex to Unpacked-Hex and vice-versa

471 views
Skip to first unread message

Ammar Farooq

unread,
Jan 16, 2004, 1:52:47 PM1/16/04
to
I have following fields

ABC character field of length 4, value = 0800 (F0F8F0F0)

and I have to convert it to

XYZ character field of length 2, value = 0800 (0800) (packed)

How is it possible ? How can I do it using any API or any utility, if
I can get the source, that will of great help to me.

Similarly, I have to do the reverse. i.e.,
2-digit character field having value (0800) (packed, not viewable
unless used F22-DSPHEX in debugger to see value )
into 4-digit character field having value (0800)

Note: I cannot use ILE RPG due to certain unavoidable restrictions.

I have tried using the following code

I IDS 4
I 1 4 Hex
I 1 2 Hex1
I B 1 20Binary

C move abc binary (value of abc is f0f8f0f0 , or
0800 - abc is 4-char)

now HEX1 has value 0320 in hexadecimal, which is 800 in decimal.
However, I need this value (0320) to be 800 in a character field of
length-2 . How can I do that ? and vise versa ?


Thanks in advance for your time and favaor

Regards
Ammar Farooq

Brian

unread,
Jan 16, 2004, 5:47:25 PM1/16/04
to
Here's some code that packs. I'll leave it to you to unpack...

"Ammar Farooq" <ammar...@yahoo.com> wrote in message
news:1d4eafdf.04011...@posting.google.com...

Dave McKenzie

unread,
Jan 16, 2004, 5:45:48 PM1/16/04
to

I DS
I 1 4 ABC
I 1 40ZONE4
I DS
I P 1 31PACK51
I 1 2 PACK2
C MOVE '0800' ABC
C Z-ADDZONE4 PACK51
*
* Now PACK51 conatins x'08000F' (decimal 0800.0)

C MOVE PACK2 XYZ 2
*
* Now XYZ contains x'0800'
*
* Do the reverse:
C Z-ADD0 PACK51
C MOVE XYZ PACK2
C Z-ADDPACK51 ZONE4

* Now ABC contains x'F0F8F0F0'
*
C SETON LR

(This assumes that ABC and XYZ always contain valid decimal digits.)

--Dave

Saml

unread,
Jan 16, 2004, 5:50:36 PM1/16/04
to
XYZ character field of length 2, value = 0800 (0800) is packed unsigned,
used only, in my experience, by mainframes.
In a length 2 packed field you can get the values -999 to +999.

If you truly want to go to length 2, packed unsigned:
Create a packed 5 0 field. (It will be 3 bytes long.)
MOVE char field to this field. Or if on V5R2, use %DEC.
Multiply field by 10.
Use a data structure to get the first 2 bytes of the field.

Sam

"Ammar Farooq" <ammar...@yahoo.com> wrote in message
news:1d4eafdf.04011...@posting.google.com...

Barbara Morris

unread,
Jan 16, 2004, 5:39:49 PM1/16/04
to
Ammar Farooq wrote:
>
> I have following fields
> ABC character field of length 4, value = 0800 (F0F8F0F0)
> and I have to convert it to
> XYZ character field of length 2, value = 0800 (0800) (packed)
>
> Similarly, I have to do the reverse. i.e.,
> 2-digit character field having value (0800) (packed, not viewable
> unless used F22-DSPHEX in debugger to see value )
> into 4-digit character field having value (0800)
>
> Note: I cannot use ILE RPG due to certain unavoidable restrictions.
>

You were on the right track before, but you need to use P not B, and a
bit of fixup because of sign half-byte in packed values.

IUNPACK IDS 4
I 1 40ZONED

IBYTE2 IDS 3
I 1 2 PACK
I 1 30PACKED

Using 1234 for example instead of 0800:

C MOVE DATA UNPACK
* UNPACK = ZONE = F1F2F3F4
C Z-ADD ZONE PACKED
* ZONE was F1F2F3F4, PACKED is now 01234F
C MULT 10 PACKED
* PACKED is now 12340F, PACK is 1234

To go the other way,
set PACKED to zero, PACKED=00000F
load your 2-byte value into PACK, PACKED=12340F
divide PACKED by 10 PACKED=01234F
Z-ADD PACKED to ZONED. UNPACK=ZONED=F1F2F3F4

0 new messages