1

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

3
  • You can write a method that uses ASCII values for this. Commented Oct 27, 2015 at 20:53
  • you are right @MichaelLiberman Commented Oct 27, 2015 at 20:53
  • Try printf \\\x$(printf '%x' input). For example: for input in {1..26}; do printf \\\x$(printf '%x' $((input+96))); done. Commented Oct 27, 2015 at 21:09

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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 ?
cnvt 35 prints a printable character i.e. ASCII code 132
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.