Is it true that endianness only affects the memory

2020-03-01 17:14发布

问题:

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



标签: endianness