'Why do upper case letters come before lower case letters in the ASCII table?
In one of my interview, the interviewer asked me why the upper case letters are before the lower case letters in ASCII table, I searched on google.com but found nothing, could anyone gave me the answer? Thx a lot!
Solution 1:[1]
To make sure that lowercase letters don't come before uppercase letters when sorting text.
In the modern Unicode era, sorting text is far more complicated, but 20 years ago, you could sort text by ASCII values.
Solution 2:[2]
Basically when sorting strings w=you want 'a' to come before 'b' and the character code of 'a' is less (smaller) than 'b'.
The same thing with uppercase. 'A' is before 'a'.
That way you can easily sort 'Anthony' before 'ant', just by comparing character codes, even though lowercase 'anthony' would normally appear just after 'ant' due to length.
That would have made sorting strings very complex if uppercase has larger character codes than lowercase.
As 'Slaks' mentioned however...Unicode makes it more complicated in you have characters such as ?AÁÀÂÄ???Ã?, which often have unicode numbers larger than 'a' but are generally considered sorting before 'a'.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SLaks |
| Solution 2 | anthony |
