Hey, I have been doing research on Endianness. I know that little Endian means that the least significant byte of any multibyte data field is stored at the lowest memory address, which is also the address of the larger field. And Big Endian means that the most significant byte of any multibyte data field is stored at the lowest memory address, which is also the address of the larger field, which they are just the opposite just switched around.

Endianness will not affect your programs performance or correctness, for as long as its use of a data structure that is on a high level is commensurate with its declaration. So this is my question....

is there a situation that even a program that does not violate this rule, you could be thrown off by the Endianness of the architecture by programs that cross networks boundaries?

Recommended Answers

All 3 Replies

Data sent over networks can have this problem, which is why there are macro functions in C that will switch one form to a neutral form (network form), and another which will take a network form number and convert it to local. This needs to be done because you might be receiving a number (16, 32, or 64 bit) from one endian, like a Sparc processor (Sun/Oracle) system, on another, like an x86 processor system, and vice versa. Some processors can be configured as either, such as MIPS or ARM processors. So, the rule is, if you get what is supposed to be a number from a network message, use the appropriate macros to convert it, and if you are sending a number over the network to another system, use the appropriate macro to convert it... :-) Anyway, this Wikipedia article gets into that in some detail, and describes the macros that I briefly described (ntohl-htonl, et al): http://en.wikipedia.org/wiki/Big-endian

Thank you i did Read that in wikipedia didnt know if it was to accurate....

From what I read, it is. Since you NEVER know what kind of machine (without jumping through some non-standard hoops) you are getting data from, you have to assume that the data is in network form (and I cannot for the life of me remember if that is big or little endian!), and so convert it accordingly. If your system is the same as the network form, then the macros basically do nothing, and the performance hit is negligible. Anyway, this is standard procedure for dealing with binary numerical data from network sources.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.