print ascii value of A

i want to print ascill value of A and also want to print A by its ascii value
please hel me.
(i know ascii of A=97)

See if this post helps you.

  • nilesh

Not sure where 97 came from for "A". maybe you mean lower case "a".
See: man ascii .

A = 101 in octal
A = 41 in hexadecimal
A = 65 in decimal

a = 141 in octal
a = 61 in hexadecimal
a = 97 in decimal

If you actually mean lower case a, you can use "bc" to change number bases from decimal to octal then use shell echo to display the character.

#!/bin/ksh
CHAR=97
OCT=`echo "obase=8;ibase=10;${CHAR}"|bc`
echo "\0${OCT}"

a

There are probably simpler ways, but I use that 'od...' command often when trying to diagnose data issues. It helps to find strange characters in text.
The first example is the decimal represenation of "A" and the second is the octal representation.

> echo "A" | od -An -t dC | awk '{print $1}'
65
> echo "A" | od -An -t oC | awk '{print $1}'
101

See Ascii value of character?

printf "%d\n" "'a"

...gives 97