How to write endian agnostic C/C++ code?

The only time you have to care about endianness is when you’re transferring endian-sensitive binary data (that is, not text) between systems that might not have the same endianness. The normal solution is to use “network byte order” (AKA big-endian) to transfer data, and then swizzle the bytes if necessary on the other end.

To convert from host to network byte order, use htons(3) and htonl(3). To convert back, use ntohl(3) and ntohs(3). Check out the man page for everything you need to know. For 64-bit data, this question and answer will be helpful.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)