Consider this:

05  INPUT-VALUE.
      10  IVC   OCCURS 5 TIMES PIC X(01).
05  OUTPUT-VALUE    PIC S9(07) DISPLAY.
05  WORK-VALUE        PIC S9(04) COMP.
05  WORK-VALUE-R    REDEFINES WORK-VALUE.
      10  FILLER              PIC X(01).
      10  WVC                  PIC X(01).
05  IX                             PIC S9(04) COMP.


    MOVE 'B1234' TO INPUT-VALUE.
    MOVE ZERO TO IX, WORK-VALUE, OUTPUT-VALUE.
    PERFORM CONVERTER 4 TIMES.
CONVERTER.
    ADD 1 TO IX.
    MOVE IVC (IX) TO WVC.
    IF WORK-VALUE < 240 THEN SUBTRACT 183 FROM WORK-VALUE
    ELSE SUBTRACT 240 FROM WORK-VALUE.
    COMPUTE OUTPUT-VALUE = OUTPUT-VALUE * 16 + WORK-VALUE
CONVERTER-END.
    DISPLAY INPUT-VALUE, ' ', OUTPUT-VALUE.

This should give you the results you want.


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[EMAIL PROTECTED] On
Behalf Of Bill Klein
Sent: Tuesday, December 18, 2007 7:00 AM
To: IBM-MAIN@BAMA.UA.EDU
Subject: Fw: Fw: Hex to Decimal Conversion in COBOL

To do this manually,
  If you have "B1234"  (each character taking 1 byte) then the "manual"
conversion would be
   (4 * (16 ** 0)) +
   (3 * (16 ** 1)) +
   (2 * (16 ** 2)) +
   (1 * (16 ** 3)) +
   (11 * (16 ** 4)

You would need to first convert A to 10, B to 11 ... F to 16

"Srini" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>
...
> 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, [EMAIL PROTECTED] (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" <[EMAIL PROTECTED]> wrote in message
> >
> >
<news:[EMAIL PROTECTED]>
...
> >
> > > 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.
> >

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to