From: Ian D Romanick Message-Id: <199703042346.PAA14837@sirius.cs.pdx.edu> Subject: Byte order (was Re: [Q] What #defines for cross-platform) To: jonc AT twinsun DOT com Date: Tue, 4 Mar 1997 15:46:33 -0800 (PST) Cc: djgpp AT delorie DOT com In-Reply-To: <331C8D16.2FD2@twinsun.com> from "Jon A. Cruz" at Mar 4, 97 12:59:02 pm MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > * byte order > > I don't want to say things like "#ifdef __INTEL__" all down in my code, > but more like "#ifdef __BIG_ENDIAN__" or "#if _BYTE_ORDER = _BIG_ENDIAN" In netinet\in.h there are two macros that take care of most of this. Use htonl() and htons() to convert a long or a short to "network byte order" (i.e., big endian), and ntohl() and ntohs() to convert back. If you need to use little endian, there is no "standard" way of doing it. However, I just put up a small library that takes care of both quite nicely. You can get it at http://www.cs.pdx.edu/~idr/byteordr.zip. -- Sign you're a demo geek: When you get drunk and think, "Hey, the world looks like a vector demo with a really bad frame rate." Demos, Compression, and Fun are located at http://www.cs.pdx.edu/~idr