How to convert numbers to the first letters of the alphabet? . I want to use this code for me. But I need alphabets for 10,11,12,13
etc. for example if the user will enter 10
, the program will print j
for 11 -->"k"
. How cam I do this.
My code is same in the link above
Asked
Active
Viewed 1,088 times
1
-
You can write a method that uses ASCII values for this. – MikeL Oct 27 '15 at 20:53
-
you are right @MichaelLiberman – esrtr Oct 27 '15 at 20:53
-
Try `printf \\\x$(printf '%x' input)`. For example: `for input in {1..26}; do printf \\\x$(printf '%x' $((input+96))); done`. – alvits Oct 27 '15 at 21:09
2 Answers
3
You can use this BASH function:
cnvt() { printf "\x$(printf '%x' $((97 + $1 -1)))\n"; }
Test it:
cnvt 10
j
cnvt 11
k
cnvt 26
z

anubhava
- 761,203
- 64
- 569
- 643
-
What I have in my answer is indeed the shell script. Just add my given inside any shell script and use it the way I suggested here. – anubhava Oct 27 '15 at 21:20
-
for example , when I write 35 , it gives me 'z' .Is it possible ? I know when I write 26 i gives 'z' . but ıt is possible for in ascii codes ? – esrtr Oct 27 '15 at 21:51
-
1
You can use ASCII table for this.
If user inputs 10 you can add 87 and get "a" = 97.
This way input 11 will get a value of "b" = 98.

MikeL
- 5,385
- 42
- 41