Given a string of English alphabets. The task is, for every character in the string print its position in the English alphabets.
Note: The characters in the string are considered to be case-insensitive. That is, both ‘A’ and ‘a’ are at first position.
Output: 7 5 5 11 19
‘G’ is the 7th character of the alphabets
‘e’ is the 5th and so on…
Output: 1 12 7 15 18 9 20 8 13 19
A letter’s position in Alphabet can easily be found by performing logical AND operation with the number 31.
Note that this is only applicable on letters and not special characters.
Every letter has an ASCII value which can be represented in binary form. Performing the bitwise and of this value with the number 31 will give the letter’s position in the alphabets.
Below is the implementation of the above approach:
7 5 5 11 19
- Count characters at same position as in English alphabet
- Find average of two numbers using bit operation
- Find position of the only set bit
- Find the value at kth position in the generated array
- Find position of the given number among the numbers made of 4 and 7
- Find position of left most dis-similar bit for two numbers
- Latin alphabet cipher
- Smallest alphabet greater than a given character
- Transform One String to Another using Minimum Number of Given Operation
- Generate number with given operation and check if it is palindrome
- Minimum operation require to make first and last character same
- Count of numbers which can be made power of 2 by given operation
- Sub-string that contains all lowercase alphabets after performing the given operation
- Form the smallest number using at most one swap operation
- Next higher number using atmost one swap operation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.