so i have a little endian formatted character in external file. Suppose 65535 (0x00 00 FF FF). In the external file, printed "0xFF 0xFF 0x00 0x00" (in ascii of course). How can I convert the character of the external file to INT32-bit number? the file reading must be in %c mode. The program "must" use C++
Asked
Active
Viewed 58 times
0
-
What did you try so far? Did you get an error? – eerorika May 06 '14 at 10:55
-
A *character* cannot be little or big endian, as `sizeof( char ) == 1`. You can have the on-file representation of a `wchar_t` affected by endianess, or that of a `char16_t`, or of a `char32_t`, which is why the recommended format for on-disk storage is UTF-8 -- which does not suffer from endianess issues. – DevSolar May 06 '14 at 10:56
-
2If the program must use (be written in?) C++, file reading "in `%c` mode" is a bit off. – Bartek Banachewicz May 06 '14 at 10:56
-
@DevSolar big fat NO. *Byte order* (aka endianness) is a property of byte sequences. All of `wchar_t`, `char16_t`, and `char32_t` are *numbers*, not byte sequences. – R. Martinho Fernandes May 06 '14 at 10:57
-
@R.MartinhoFernandes: ...talking about their representation in external storage. Should have been clearer about that. Fixed. – DevSolar May 06 '14 at 10:57
-
Check [Byte order mark](http://en.wikipedia.org/wiki/Byte_order_mark), [man htonl](http://linux.die.net/man/3/htonl), and most importantly, [International Components for Unicode (ICU)](http://site.icu-project.org/). Also, possible duplicate of [How do I convert between big-endian and little-endian values in C++?](http://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c) – DevSolar May 06 '14 at 11:06