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