1287. Find Upper and Lower Case of a Character

EasyBit ManipulationBit ManipulationASCIIBit Trick

For ASCII letters, bit 5 (value 32) distinguishes case: uppercase letters have it clear and lowercase have it set. Given the ASCII code of a byte, return the pair [code | 32, code & ~32]. For English letters these are exactly the lowercase and uppercase codes; in general the operation sets and clears bit 5.

Input: A JSON object {"code": <byte value>} with 0 <= code <= 255.

Output: Return a two-element array [code with bit 5 set, code with bit 5 cleared].

Examples

Example 1
Input: {"code":65}
Output: [97,65]
Explanation: 'A' | 32 = 97 ('a'); 'A' & ~32 = 65 ('A') -> [97,65].
Example 2
Input: {"code":104}
Output: [104,72]
Explanation: 'h' | 32 = 104 ('h'); 'h' & ~32 = 72 ('H') -> [104,72].

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →