Convert Character String to Hex 
Author Message
 Convert Character String to Hex

Quote:

>I have noticed several suggestions, more or less complicated, and
>those using the PACK instruction all seem to overlook that this
>instruction needs a garbage byte for the source as well as for the
>target field. (The source field garbage byte is not modified, so it
>can be anything, even a valid byte belonging to another field, but it
>must be addressable)

Many years ago I had a fortran program, which printed some data in
hex using FORTRAN formatted I/O.  Everything worked fine until I
decided to build a load module, instead of using the LOADER.  Then
the program failed on an 0C4 abend.

It turned out that the data I was converting to hex was right at the
end of the module (in a COMMON area).  It turned out that the program
was being loaded right-aligned on a page boundary, and the source
garbage byte was on the next page and protected since that page had
not been assigned to the job.



Sat, 25 Aug 2001 03:00:00 GMT  
 Convert Character String to Hex
Sven,

I have a second suggestion:

TRANSTBL    DS    0CL26
                        DC    XL7'F0FAFBFCFDFEFF'
                        DC    CL19'0000000000123456789'
ANDTBL        DC    16X'1F'

WORKCL16  DS    CL16
WORKXL9    DS    XL9

                        MVC    WORKCL16,=C'0123456789ABCDEF'
                        NC        WORKCL16,ANDTBL
                        TR        WORKCL16,TRANSTBL
                        PACK    WORKXL9,WORKCL16
                        MVO    WORKXL9,WORKXL9

* BYTES 1-8 CONTAIN X'0123456789ABCDEF'.
* THE NINTH BYTE WE DON'T CARE ABOUT.
* YOU MUST DO AN MVO OF ITSELF. SRP WILL FAIL.

Cheers,

WOB

Quote:

>I have noticed several suggestions, more or less complicated, and those
>using
>the PACK instruction all seem to overlook that this instruction needs a
>garbage
>byte for the source as well as for the target field. (The source field
>garbage byte
>is not modified, so it can be anything, even a valid byte belonging to
>another
>field, but it must be addressable)

<Rest Snipped>


Sat, 25 Aug 2001 03:00:00 GMT  
 Convert Character String to Hex
Yes, I suppose this will work (although I haven't validated the
 code in detail). Incidently, I notice that you introduce the need
for an MVO instruction after the PACK to compensate for the
failure to have a "garbage" byte after both fields referenced in
the PACK.

  However, I have one major objection against your code, not on
the functionality, but on what I call "visibility":

It is not in my opinion immediately easy to see exactly what the
code does compared to the straight forward translate and pack
instruction sequence. This lack of "visibility" in your code will
 seriously increase the danger of undesired side-effects if any
 maintenance to the program containing this code is ever needed.

Besides, using the full translate table also facilitates an easy
 validation on the input field if that is desirable.

By the way, have you noticed how your code behaves if the
 input field contains any byte in the ranges b'???11010' to b'???11111'  ?

regards Sven


Quote:
>Sven,

>I have a second suggestion:

>TRANSTBL    DS    0CL26
>                        DC    XL7'F0FAFBFCFDFEFF'
>                        DC    CL19'0000000000123456789'
>ANDTBL        DC    16X'1F'

>WORKCL16  DS    CL16
>WORKXL9    DS    XL9

>                        MVC    WORKCL16,=C'0123456789ABCDEF'
>                        NC        WORKCL16,ANDTBL
>                        TR        WORKCL16,TRANSTBL
>                        PACK    WORKXL9,WORKCL16
>                        MVO    WORKXL9,WORKXL9

>* BYTES 1-8 CONTAIN X'0123456789ABCDEF'.
>* THE NINTH BYTE WE DON'T CARE ABOUT.
>* YOU MUST DO AN MVO OF ITSELF. SRP WILL FAIL.

>Cheers,

>WOB


>>I have noticed several suggestions, more or less complicated, and those
>>using
>>the PACK instruction all seem to overlook that this instruction needs a
>>garbage
>>byte for the source as well as for the target field. (The source field
>>garbage byte
>>is not modified, so it can be anything, even a valid byte belonging to
>>another
>>field, but it must be addressable)

><Rest Snipped>



Sun, 26 Aug 2001 03:00:00 GMT  
 Convert Character String to Hex
Actually, there's no need to wonder. This works as advertised and just as
well as the 256-Byte Translate-Table, but with reduced storage.

The subtlety with the MVO (basically a non-decimal SRP Label,1,0) is
actually the way I execute this normally. But, that's my preference. As I
eluded to, if you substituted an SRP for the MVO, you'd be S.O.L. when any
nibbles are in the range of B'1010' through B'1111'.

Once a canned-routine like this is in-place, maintenance should not be an
issue. It should be a BALR'd Sub-Program, link-edited with the Caller's Load
Module (CICS) or Dynamically-Called (Batch). Believe it or not, I've got a
COBOL2 version of this almost as efficient, except that it uses a 256-Byte
Translate-Table by default. E-Mail me if you'd like a copy ===>

Regarding the 'AND' mask. Yes, I'm aware of this. But, I must assume that
the person knows that only EBCDIC 0-9 and the letters A-F can be converted
into 4-bit nibbles. If they attempt to convert other than these values, then
they should take a refresher course in DP101.

Cheers,

WOB

Yes, I suppose this will work (although I haven't validated the
 code in detail). Incidently, I notice that you introduce the need
for an MVO instruction after the PACK to compensate for the
failure to have a "garbage" byte after both fields referenced in
the PACK.

  However, I have one major objection against your code, not on
the functionality, but on what I call "visibility":

It is not in my opinion immediately easy to see exactly what the
code does compared to the straight forward translate and pack
instruction sequence. This lack of "visibility" in your code will
 seriously increase the danger of undesired side-effects if any
 maintenance to the program containing this code is ever needed.

Besides, using the full translate table also facilitates an easy
 validation on the input field if that is desirable.

By the way, have you noticed how your code behaves if the
 input field contains any byte in the ranges b'???11010' to b'???11111'  ?

regards Sven



Sun, 26 Aug 2001 03:00:00 GMT  
 Convert Character String to Hex


Quote:
> I have noticed several suggestions, more or less complicated, and those
using
> the PACK instruction all seem to overlook that this instruction needs a
garbage
> byte for the source as well as for the target field.

If the target field is part of a structure it is not always possible to use
the next byte as garbage byte, and if the source field is at the end of a
page you may get an interrupt if you use the next byte as a garbage byte
and the next page is not valid.

However, there is no need for garbage bytes, just use two instructions:

PACK  TARGET,SOURCE(L'SOURCE-1)
MVN    TARGET+L'TARGET-1(1),SOURCE+L'SOURCE-1

Of course this is only safe for values 0-9, you will have to add
translation if A-F may occur, and validity control if other values may
occur.



Mon, 27 Aug 2001 03:00:00 GMT  
 Convert Character String to Hex

Quote:

> I find it very interesting that there are so many BAL programmers out
> there!!!!  But, where are the jobs to support us folks?????  Seems to me
> that we are being put to pasture!!!! any suggestions???


It seems that you'd pretty much need to confine a job search to software
development firms, or seek independent contracting or consulting
opportunities.  Even "systems programmers" are afforded little
opportunity to write in assembler these days.

    -jc-



Tue, 28 Aug 2001 03:00:00 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. convert string to hex characters in TCL

2. Reading a hex string of 4 hex characters

3. Convert a hex string to the same hex number

4. Fast conversion of hex string to character string

5. Converting hex digit to ASCII character

6. Converting hex digit to ASCII character

7. Bug in character string hex formatting

8. Converting hex string values to numeric

9. How to convert hex string to number?

10. Converting dec to hex in non-string format?

11. convert hex #'s and letters to one string constant

12. Converting A string representation of a dec to an Hex

 

 
Powered by phpBB® Forum Software