This is a cheap ASCII trick, that only works for that particular encoding. It is not recommended. But to answer your question, the reverse operation involves masking instead of combining:
sb.Append((char)(c & ~32));
Here, you take the bitwise inverse of 32
and use bitwise-AND. That will force that single bit off and leave others unchanged.
The reason this works is because the ASCII character set is laid out such that the lower 5 bits are the same for upper- and lowercase characters, and only differ by the 6th bit (32
, or 00100000b
). When you use bitwise-OR, you add the bit in. When you mask with the inverse, you remove the bit.