Encode unicode codepoints to UTF-8 manually
Yes, the code is correct for all valid code points. I was first confused about the double shifts, since I have never seen them before, but they do their job well. Other authors typically do a single &gt;&gt; followed by a bit mask, e.g. (codepoint &gt;&gt; 12) &amp; 0x3F to skip the 12 bits to the right and take the next 6 bits. That way, the numbers can be verified more easily, since they are smaller. Plus, all the 01xxxxxx bytes have the same bitmask.

Your code omits some validity checks:


codepoint could be &lt; 0
codepoint could be between 0xD800 and 0xDFFF


Other than these, it is perfect.

I know for sure that this conversion is built-in into C#, I just don't know where. Try loading a file into a string using the UTF-8 encoding. During that loading, the built-in conversion code gets called.