Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

endianness

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.

like image 336
compile-fan Avatar asked Apr 27 '11 13:04

compile-fan


People also ask

Are strings affected by endianness?

Endianness and Character DataIf you store any ASCII character string in memory, it always looks the same, no matter what the Endianness of the hardware, since each character is one byte long and the start character of the string is always stored at the lowest memory location.

What does endianness depend on?

Broadly speaking, the endianness in use is determined by the CPU. Because there are a number of options, it is unsurprising that different semiconductor vendors have chosen different endianness for their CPUs.

What is memory endianness?

Endianness is a term that describes the order in which a sequence of bytes is stored in computer memory. Endianness can be either big or small, with the adjectives referring to which value is stored first.

How is memory stored in little endian?

Little Endian Byte Order: The least significant byte (the "little end") of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory. In these definitions, the data, a 32-bit pattern, is regarded as a 32-bit unsigned integer.

Why do we write numbers in big-endian?

We write numbers in big endian order And that is unnatural, because in order to read a big number, we need to: jump to the end of a number. scan right-to-left, counting groups of 3 digits, to figure out the order (thousands, millions) then, knowing the order, we can say the number.

Are arrays affected by endianness?

Note: Endianness does NOT affect ordering of array elements! However, endianness does affect the ordering of the bytes in each element of the array!


2 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).

like image 92
Oliver Charlesworth Avatar answered Oct 19 '22 07:10

Oliver Charlesworth


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

like image 33
Klas Lindbäck Avatar answered Oct 19 '22 07:10

Klas Lindbäck