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.
-
Is there a processor architecture out there with native string support? Characters are just numbers. – Wooble Apr 27 '11 at 13:26
4 Answers
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).

- 267,707
- 33
- 569
- 680
-
I know that little endian means the least significant byte is restored at the lowest address,but that's the case for a number,what about for string? – compile-fan Apr 27 '11 at 13:34
-
@compile-fan: See e.g. http://en.wikipedia.org/wiki/UTF-16#Byte_order_encoding_schemes. – Oliver Charlesworth Apr 27 '11 at 13:35
-
For strings of 1-byte characters that is correct. For unicode strings (2 bytes/character) there will be a difference.

- 33,105
- 5
- 57
- 82
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.

- 31,254
- 3
- 43
- 68
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

- 5,527
- 1
- 24
- 38
-
I know how endian affects numbers,but I don't know whether it affects ascii string. – compile-fan Apr 27 '11 at 13:43
-
1No it does not affect ASCII strings, because ASCII characters are a single byte, and a string is simply an array of characters. It's the same as an array of numbers; the ordering of the numbers doesn't change, but the ordering of bytes within each number does change. – jhocking Apr 27 '11 at 14:18