I want to convert the endianness of an UTF-16 character array stored as wchar_t*
. Assuming sizeof(wchar_t) == 2
in this case.
Converting from BE to LE and LE to BE are both needed so ntoh/nton doesn't work.
I've read How do I convert between big-endian and little-endian values in C++? but I'm not sure how to apply it to a wchar_t
.
Is there a way to swap the 2 bytes of a wchar_t
? Or do I have to convert it to binary first?
EDIT: Though I didn't test all answers, I believe they all works. That said, I think Jarod42's answer is more straightforward.