convert to ASCII

convert to ASCII

Post by Marc » Sat, 16 Feb 2002 00:33:47



Hello,

is there a simple way to convert a number to its ASCII representation.
eg : 65 => 'A'

Thanks in advance.

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/

 
 
 

convert to ASCII

Post by Derek M. Flyn » Sat, 16 Feb 2002 02:26:06



>  is there a simple way to convert a number to its ASCII representation.
>  eg : 65 => 'A'

I would have thought that printf(1) would be the best way, but it doesn't
seem to work.  However, any means of getting at the actual printf(3) will
give you what you want.  An example in awk is:

$ awk 'BEGIN { printf("%c\n", 65); exit }'
A

 
 
 

convert to ASCII

Post by Robert Sherm » Sat, 16 Feb 2002 02:27:26



> Hello,

> is there a simple way to convert a number to its ASCII representation.
> eg : 65 => 'A'

well, it ain't shell, but...
perl -e 'print chr(65) . "\n"'

solaris has a chart of hex/oct to ascii in /usr/pub/ascii...
you could parse that. the man page has a decimal version, though
the actual file does not...hmmm....

--
robert sherman
css3, school of civil and environmental engineering
georgia institute of technology
atlanta, ga, usa

 
 
 

convert to ASCII

Post by Ben Altma » Sat, 16 Feb 2002 02:16:00



Quote:

> Hello,

> is there a simple way to convert a number to its ASCII representation.
> eg : 65 => 'A'

    awk 'BEGIN { printf("%c\n", 65); }'
or more generally (if char is a value):
    awk -v CHAR=$char 'BEGIN { printf("%c\n", CHAR); }'

regards,
Ben

 
 
 

convert to ASCII

Post by Chris F.A. Johnso » Sat, 16 Feb 2002 02:54:42



Quote:> Hello,

> is there a simple way to convert a number to its ASCII representation.
> eg : 65 => 'A'

        d2c() { ## USAGE: d2c NNN  - NNN = decimal number
            eval  echo `printf "\$'\\\x%x'\n" $1`
        }

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

convert to ASCII

Post by Chris F.A. Johnso » Sat, 16 Feb 2002 03:19:12




> > Hello,

> > is there a simple way to convert a number to its ASCII representation.
> > eg : 65 => 'A'

>    d2c() { ## USAGE: d2c NNN  - NNN = decimal number
>        eval  echo `printf "\$'\\\x%x'\n" $1`
>    }

Slashed when trying to escape!

        d2c() {
            eval  echo `printf "\$'\\\\\x%x'\n" $1`
        }

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

convert to ASCII

Post by Ben Altma » Sat, 16 Feb 2002 03:08:34






> > > Hello,

> > > is there a simple way to convert a number to its ASCII representation.
> > > eg : 65 => 'A'

> > d2c() { ## USAGE: d2c NNN  - NNN = decimal number
> >     eval  echo `printf "\$'\\\x%x'\n" $1`
> > }

> Slashed when trying to escape!

> d2c() {
>     eval  echo `printf "\$'\\\\\x%x'\n" $1`
> }

It worked the original way on bash.
regards,
Ben
 
 
 

convert to ASCII

Post by Chris F.A. Johnso » Sat, 16 Feb 2002 03:51:37







> > > > Hello,

> > > > is there a simple way to convert a number to its ASCII representation.
> > > > eg : 65 => 'A'

> > > d2c() { ## USAGE: d2c NNN  - NNN = decimal number
> > >     eval  echo `printf "\$'\\\x%x'\n" $1`
> > > }

> > Slashed when trying to escape!

> > d2c() {
> >     eval  echo `printf "\$'\\\\\x%x'\n" $1`
> > }

> It worked the original way on bash.

With only 3 slashes I get (in bash):

        $ d2c 77
        bash: printf: missing hex digit for \x
        M

The whole thing only works, apparently, on bash and ksh93.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

convert to ASCII

Post by Barry Margoli » Sat, 16 Feb 2002 06:19:59




>is there a simple way to convert a number to its ASCII representation.
>eg : 65 => 'A'

perl -e 'print chr(65), "\n"'

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

convert to ASCII

Post by Peter J. Ackl » Sat, 16 Feb 2002 17:55:37





> > is there a simple way to convert a number to its ASCII representation.
> > eg : 65 => 'A'

> Smaller than perl or awk:

> echo 65P | dc

Really neat.  Although the Perl solution

   perl -e 'print chr(65), "\n"'

presented by someone else, can be reduced to

   perl -le 'print chr 65'

Peter

--
People say I'm indifferent, but I don't care.

 
 
 

convert to ASCII

Post by Marc » Sat, 16 Feb 2002 18:37:41


Thanks to all,

The solution with 'echo' doesn't work for me.
And, as I use a variable for 65, 66, etc, I use awk which works perfectly.

Thanks again.

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/

 
 
 

convert to ASCII

Post by laura fairhe » Tue, 19 Feb 2002 12:08:10





>> is there a simple way to convert a number to its ASCII representation.
>> eg : 65 => 'A'

>Smaller than perl or awk:

>echo 65P | dc

hi hactar :)

This doesn't work in all versions of 'dc', values 1-99
seem to always work but above that it's implementation
dependant and systems I've seen that fail (IIRC: HP-UX, SunOS)
output the string that is the base-100 expansion of the
value (eg; 100-> 0,1 outputs nothing 165-> 65,1 outputs A,\01 )

It's safer to use 'tr';

echo z|tr 'z' \\`echo 8o65p|dc`

>--

>GEMINI:  Your birthday party will be ruined once again by your explosive
>flatulence.  Your love life will run into trouble when your fiancee hurls a
>javelin through your chest.  -- Weird Al, _Your Horoscope for Today_

byefrom

--

                # http://lf.8k.com   http://lf.1accesshost.com

 "Perfection is achieved, not when there is nothing more to add,
 but when there is nothing left to take away" (Antoine de Saint-Exupery)

 
 
 

1. Need sed script to convert Mac ascii to Unix ascii

We have consultants delivering jsp files in Mac ascii format.  We need
them in Unix ascii format.  Does anyone have a mac to Unix utility or
can someone tell me how to do it using sed?

Thanks

BTW,  Mac ascii files have lines ending in the character CR  or 0D.
Unix of course is CRLF  or ODOA.

Thanks

2. Linux PPC860 ....

3. Converting Mac ascii to Unix ascii?

4. can't mount Sony cdu31a

5. Converting Mac ASCII files to UNIX

6. proxy arp/PPP

7. Converting an ASCII file to a Binary File

8. For Two NIC -> Two Entries in /etc/hosts

9. Can tex files be converted to ASCII files

10. Convert aix ascii file to dos

11. Print files with formatting codes, convert to ASCII?

12. how to convert paper.ascii.gz to plain text?

13. Is there a utility to convert an ASCII string in a binary file?