If I want to convert UTF-16 BE <-> LE, what should I consider? Can I treat them just a plain 2-byte integer array? Or should I follow some special Unicode algorithm to handle some exceptional case?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You just need to byte-reorder the code units, thus taking two bytes, swapping them and writing them back. That is all there is to consider.
But usually there is a simple way of reading a stream in one encoding and writing it back in another encoding. Often with negligible performance drawbacks (especially in the UTF-16 case). So to make your code clearer you should probably opt for such a solution. But the trivial way should work regardless
if you know the input encoding precisely.