Help: convert character to ASCII code? 
Author Message
 Help: convert character to ASCII code?


 >My problem is, as the title said, how to convert a character to
 >its corresponding ASCII code.  For example, suppose that I got a
 >character "A", how can I get its ASCII code, 65?  I only know how
 >to do the reverse( sprintf("%c", 65) ), so if there's a way to do
 >this, please share the knowledge.  Thanks in advance.

BEGIN {
        for(i=0;i<256;i++)
            all=all sprintf("%c",i)
      }

{
        print index(all,substr($0,1,1))

Quote:
}

Version dependancies:  sprintf() is not in older awks, but then you mentioned
yours had it... very old awks do not have index(), and indeed it is not
named in my man page (although it seems to have it anyway).  SGI's "nawk"
has both, and that is what I used to test the above. Your results may vary.

--

                                                         (519)824-4120x6309



Sun, 12 Apr 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Convert Character to ASCII code in 8086 Help!

2. Summary: convert character to ASCII code?

3. Converting Characters to Ascii code

4. Converting Character to ASCII in 8086, Help! (again)

5. Help- convert ascii code into char strings

6. Newbie: converting character to ascii representation

7. convert character to ascii

8. Converting STD_LOGIC_VECTOR to ASCII character

9. Converting hex digit to ASCII character

10. Converting hex digit to ASCII character

11. Converting ASCII characters <-> binary string

12. Convert character to ascii value

 

 
Powered by phpBB® Forum Software