I was solving some problem on codeforces. Normally I first check if the character is upper or lower English letter then subtract or add
32 to convert it to the corresponding letter. But I found someone do
^= 32 to do the same thing. Here it is:
char foo = 'a'; foo ^= 32; char bar = 'A'; bar ^= 32; cout << foo << ' ' << bar << '\n'; // foo is A, and bar is a
I have searched for an explanation for this and didn't find out. So why this works?