Is it true that endianness only affects the memory layout of numbers,but not string?

[亡魂溺海] 提交于 2019-11-30 03:18:36

问题


Is it true that whether the architecture is big or little endian ,only the memory layout of numbers differ,that of the string is the same.


回答1:


If you have a simple 8-bit character representation (e.g. extended ASCII), then no, endianness does not affect the layout, because each character is one byte.

If you have a multi-byte representation, such as UTF-16, then yes, endianness is still important (see e.g. http://en.wikipedia.org/wiki/UTF-16#Byte_order_encoding_schemes).




回答2:


For strings of 1-byte characters that is correct. For unicode strings (2 bytes/character) there will be a difference.




回答3:


That's generally not true. Depending on the circumstances, more than one byte might be used for characters, in which case there is a difference between little endian encoding of characters and big endian encoding of characters.




回答4:


For the most part, but you should understand why. Big vs little endian refers to the ordering of bytes in multi-byte data types like integers. ASCII characters are just a single byte.

Note however that unicode characters are multiple bytes, so the byte order matters. The entire point of unicode is that the single byte in ASCII can only encode 256 different values, which is not enough for all the languages in the world.

Refer here for more informantion about what endianness means: http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html



来源:https://stackoverflow.com/questions/5804824/is-it-true-that-endianness-only-affects-the-memory-layout-of-numbers-but-not-str

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!