Skip to main content

Posts

Showing posts from October, 2010

ASCII Magic for Upper and Lower case

We've 26 alphabets in English and using ASCII code we're representing it in the computer system. As an example, 'A' is represented as 65 in decimal, and 'a' is represented as '97' in decimal. Now check the binary counterpart of 65 and 97. 65 = 01000001 97 = 01100001 From the above binary representation, it's quite clear that the upper case letter differs from the lower case letter in binary representation, exactly in a one-bit position. The above example shows these two codes differ in the 5th bit. This is true for all 26 English alphabets and can easily be deduced to an implementation in C++ to convert any lower-case English letter to an upper-case letter. The following code demonstrates it: #define toUpper(ch) ((ch >= 'a' && ch <='z') ? ch & 0x5f : ch) int _tmain(int argc, _TCHAR* argv[]) { printf("Upper case conversion: %c\n", toUpper('b')); return 0; } *Inspired by Great Peo...