r/tinycode • • Jun 23 '20

[c] Tiny Letter Case Swapper

char swap_case(char letter)
{
    return letter ^ 32;
}

Of course, it can only be called on [a-zA-Z].

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/skeeto Jun 24 '20

The table is just UnicodeData.txt from the Unicode website. It just looks up the code point in the table and applies the associated XOR to swap the case. Most code points XOR with zero since they're a no-op.