View previous topic :: View next topic |
Author |
Message |
ssd Beginner
Joined: 24 Mar 2006 Posts: 25 Topics: 10
|
Posted: Tue Aug 08, 2006 11:52 pm Post subject: How to convert a decimal value to hex in COBOL ? |
|
|
Is there any in-built function in COBOL to convert a decimal value into a hexadecimal value ? Also how to unpack a COMP-5 value and display it on the console ? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Aug 09, 2006 7:12 am Post subject: |
|
|
Quote: |
Is there any in-built function in COBOL to convert a decimal value into a hexadecimal value ?
|
SSD,
No. There is no in-built function for the conversion. Check this link which shows you an example of converting to hex
http://www.mvsforums.com/helpboards/viewtopic.php?t=2592&highlight=hex
Quote: |
Also how to unpack a COMP-5 value and display it on the console ?
|
You can use DISPLAY the comp-5 field and it will displayed in the sysout.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
|
Back to top |
|
|
ssd Beginner
Joined: 24 Mar 2006 Posts: 25 Topics: 10
|
Posted: Wed Aug 09, 2006 11:45 pm Post subject: |
|
|
Kolusu,
What if the number to be converted to hex is a negative interger ?
Regarding the display of COMP-5 the display shows some unreadable characters but once the COMP-5 is move to Zoned-decimal variable I could view the original value.
Thanks for your Replies
SSD |
|
Back to top |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Thu Aug 10, 2006 6:41 am Post subject: |
|
|
SSD,
Try this code for a sample negative input:
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD *
-0065781053
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,11,HEX)
/*
//
OUTPUT
60F0F0F6F5F7F8F1F0F5F3
|
_________________ Shekar
Grow Technically |
|
Back to top |
|
|
ssd Beginner
Joined: 24 Mar 2006 Posts: 25 Topics: 10
|
Posted: Mon Aug 14, 2006 11:42 pm Post subject: |
|
|
Shekar and Kolusu ,
Thanks for your replies..
They are extremely helpful
SSD |
|
Back to top |
|
|
anit.mohanty Beginner
Joined: 20 Jun 2015 Posts: 1 Topics: 0
|
Posted: Mon Jun 22, 2015 6:48 am Post subject: Conversion of Decimal to HEX |
|
|
Hi All,
I wrote a progarm to get the BASE 16 Hex equivalent of a Decimal Number.
So if the input is 978, the program gives 03D2.
Now I want to write 03D2 into a X(2) field in COBOL.
When I move hardcoded X'03D2' into X(02) , it works
but when I declare the same in Working storage and move the variable into
the X(2) , it does not work.
Can anybody please help ? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Jun 22, 2015 11:59 am Post subject: Re: Conversion of Decimal to HEX |
|
|
anit.mohanty wrote: | Hi All,
I wrote a progarm to get the BASE 16 Hex equivalent of a Decimal Number.
So if the input is 978, the program gives 03D2.
Now I want to write 03D2 into a X(2) field in COBOL.
When I move hardcoded X'03D2' into X(02) , it works
but when I declare the same in Working storage and move the variable into
the X(2) , it does not work.
Can anybody please help ? |
What do you mean it is not working? can you show us the code? Here is a sample.
Code: |
WORKING-STORAGE SECTION.
01 WS-A PIC X(02) VALUE X'03D2'.
01 WS-B PIC X(02) VALUE SPACES.
01 WS-C PIC X(02) VALUE SPACES.
PROCEDURE DIVISION.
MOVE WS-A TO WS-B
MOVE X'03D2' TO WS-C
DISPLAY 'WS-B IS : ' WS-B
DISPLAY 'WS-C IS : ' WS-C
|
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
|
|