Re: Fw: Hex to Decimal Conversion in COBOL
- From: "Anonymous" <com@xxxxxxx>
- Date: Tue, 18 Dec 2007 13:50:06 GMT
I don't know why a COBOL source solution is absolute-
ly necessary, but this is what I would do:
01 filler.
05 hexdata pic x(05).
inspect hexdata
converting "abcde"
to "ABCDE".
Of course, I just plugged some values so I could easily
reference their placement.
First, the "abcde" string would be replaced by the entire 255 hex
representation(s). Obviously, this will result in unprintable characters in
your source program. (more about that later).
Next, the "ABCDE" string would be replaced by the
entire 255 character representation(s). This will result
in unprintable characters also.
The first string is used to locate your byte value now
contained in "hexdata". The second string is used to
locate the new byte value substitution in "hexdata",
at the byte location currently under inspection.
Even though many techniques are used in assembly,
this is the most straightforward technique commonly
referred to as TRanslate.
If I was happy with this preliminary testing, I would
then see if I could convince cobol to let me code some-
thing like:
inspect hexdata
converting X"8182838485"
to "ABCDE".
Then, if so, you'll not have to deal with the unprintable
characters in the code listing. But, I wouldn't hold out
too much hope on the specification of a hex string.
Alternatively, it looks like the strings can also be subst-
ituted by identifiers, will value specifications. I know
you can certainly code a hex value constant.
But, editors allow hex entry transition, so even though
the strings may/will contain unprintable characters, they
can be easily manipulated.
Obviously, if you want to preserve the value of "hexdata",
you'll have something like:
01 filler.
05 hexdata pic x(05).
05 character-data pic x(05).
move hexdata character-data.
inspect character-data
converting X"8182838485"
to "ABCDE".
print character-data.
I think(IMO) this is by far the easiest, best documented
solution. And, offers long string capabilities where other
numeric manipulations fall short.
"last example":
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/igypg205/1.6.5.1?ACTION=MATCHES&REQUEST=inspect&TYPE=FUZZY&SHELF=IGYSH212&DT=20000925141919&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT
"Srini" <gubbasrini@xxxxxxxxx> wrote in message
news:e9a216a6-3d5d-461c-8a9d-0ef864bd614d@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks a lot for reply. Yes. I am receiving the data as PIC X(5) with
HEX values in it like "B1234". Do you have any example of this
conversion?. What is "manual" base-16 to base-10 conversions?
Appreciate your help.
Srini
On Dec 17, 10:45 am, wmkl...@xxxxxxxxxxxxx (Bill Klein) wrote:
When you say
5 character HEX value
Do you mean something like PIC X(10) with values of "A12F33FFdd" - or do
you
mean that you are actually receiving data in "binary" which you are
considering "hex"? If it is something like the first example, then the
most common way to "solve" this in COBOL is by creating a 256 byte table
and
of hex bytes - and then do a SEARCH ALL to convert from the location in
the
table to the decimal value of that single hex-byte-value. Other methods
do
"manual" base-16 to base-10 conversions.
"Srini" <gubbasr...@xxxxxxxxx> wrote in message
<news:ce705d31-4afe-4140-a058-140b87145558@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
I am receiving 5 character HEX value from a file and the requirement
is to convert the 5 character HEX value to Decimal in a COBOL program.
Is there any function/verb available in COBOL to convert the HEX vale
to Decimal?
Thanks in advance.
Srini
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@xxxxxxxxxxx with the message: GET IBM-MAIN INFO
Search the archives athttp://bama.ua.edu/archives/ibm-main.html
.
- References:
- Fw: Hex to Decimal Conversion in COBOL
- From: Bill Klein
- Re: Fw: Hex to Decimal Conversion in COBOL
- From: Srini
- Fw: Hex to Decimal Conversion in COBOL
- Prev by Date: Re: IFASMFDP Abends
- Next by Date: Re: Exploiting Parallel Access Volumes
- Previous by thread: Re: Fw: Hex to Decimal Conversion in COBOL
- Next by thread: Fw: Fw: Hex to Decimal Conversion in COBOL
- Index(es):
Relevant Pages
|