0

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?

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by rubberman
0

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

Edited by rubberman: n/a

0

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

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.