I recently saw a piece of code that converts a char to lowercase, and if it is already in lowercase, it remains the same.
char c = 'A';
c |= ' ';
I am trying to write code that can convert char to uppercase without using the toupper function .
Currently, the easiest way I can think of is with the code below.
char c = 'a';
c = (c | ' ') - ' ';
So, I am wondering if there is code that is simpler than this and can achieve the same results.
Any help is appreciated.
A brief description of the first code block
Char | ASCII Code
' ' | 13
'A' | 65
'a' | 97
and operator orfor manipulating bits
01000001 (char 'A')
Or 00100000 (char ' ')
= 01100001 (char 'a')
----------------------
01100001 (char 'a')
Or 00100000 (char ' ')
= 01100001 (char 'a')
source
share