+1  A: 

If your source character set is ISO 8859-1 or 8859-15 (both of which have LATIN SMALL LETTER N WITH TILDE at code point 0xF1 = 241), then the conversion needs to create the correct encoding for Unicode character U+00F1.

Now, we need to know which Unicode encoding scheme you are using. If you use UTF-8, you will need the result:

 \xC3 \xB1

If you use UTF-16 BE (big endian), you need:

\x00 \xF1

If you use UTF-16 LE (little endian), you need:

\xF1 \x00

If you are using UTF-32, then you need 4 bytes instead of 2.

And if you want a string, you will need to encode the U+0000 (NULL) as a following character.

If you don't know which form you need, you have big problems; to use Unicode, you need to understand something of how the different forms are encoded. Your library may save you from a lot of the bother of understanding, but ultimately, you need to know at least a minimum about Unicode.

Jonathan Leffler