View previous topic :: View next topic
|
Author |
Message |
SayantaniKundu
New User
Joined: 24 Nov 2008 Posts: 6 Location: Kolkata
|
|
|
|
How to convert character to decimal in cobol program.?
In the source code char say 'A' is accepted. But the decimal value of 'A' is validated against some logic.
Please suggest how to achieve this situation in cobol program? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
It is hard to decipher just what you are asking.
Ask a colleague to read your post and tell you what s/he thinks the question is. |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
Why do you think 'A' has a decimal value? It would be better to post the actual requirement to get realistic solutions. |
|
Back to top |
|
|
SayantaniKundu
New User
Joined: 24 Nov 2008 Posts: 6 Location: Kolkata
|
|
|
|
The code accepts data like 'A' , 'B' etc..
Now the HEX value of 'A' is C1... If C1 is converted to decimal (i.e. HEX to Decimal) , u get 193.
I would like to know if we can do this conversion in cobol code. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Function ORD (inp-char) |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
Declare a working storage array having two columns and 26 occurances. Col1 contains character and col2 contains decimal value.
You've got yourself a conversion table. |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
PeterHolland wrote: |
Function ORD (inp-char) |
That simple? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
to all of You ....
it would be wise to review the different number representations
see for hints
ibmmainframes.com/viewtopic.php?t=40254&highlight=
the question is badly posed
the common sense tells that a CHAR represents a number itself
what You are probably asking for is how to convert a generic byte to the decimal equivalent,
in other words an HEX to DECIMAL NOT a CHAR to DECIMAL |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Bharath Bhat wrote: |
PeterHolland wrote: |
Function ORD (inp-char) |
That simple? |
Yes. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
c /to all of You .... /to some of You .... / |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
SayantaniKundu wrote: |
The code accepts data like 'A' , 'B' etc..
Now the HEX value of 'A' is C1... If C1 is converted to decimal(i.e. HEX to Decimal) , u get 193.
I would like to know if we can do this conversion in cobol code. |
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
it would be wiser in these cases to post the full requirement
common sense tells that ...
c'A' ==> positive 1 ( zoned decimal )
or as an alternative
c'A' ==> printable for hex "A"
c''0123456789ABCDEF' ==> x'000102030405060708090a0b0c0d0e' |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
To be accurate, you need to subtract 1 from the FUNCTION output. FUNCTION ORD returns a value in the range of 1 to 256, whereas the collating sequence values are 0 to 255. The function returns 194 for an upper case A, not 193. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Robert Sample wrote: |
To be accurate, you need to subtract 1 from the FUNCTION output. FUNCTION ORD returns a value in the range of 1 to 256, whereas the collating sequence values are 0 to 255. The function returns 194 for an upper case A, not 193. |
Yes Robert, and i left that to the TS to find out. |
|
Back to top |
|
|
|