Talk:MathGem:Endian Operations

From GPWiki

Files:GUITutorial_warn.gif The Game Programming Wiki has moved! Files:GUITutorial_warn.gif

The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server.

However, the GPWiki forums are still active! Come say hello.

Strange, I've used htons and ntohs before and didn't notice that they were doing the same thing as those macros. I guess the macros are still relevant if you don't want to include the headers just to get the conversion functions. Codehead 04:01, 16 Jan 2005 (EST)

Well, htons and friends don't necessarily do anything, but if you're using Intel or AMD architecture, they do. Network byte order is big-endian and Intel/AMD (aka, the "host") byte order is little-endian, so it would convert that. Mac PPC's are big-endian, meaning htons would have no effect on the Mac platform. So, if you need to change endianness, use your macros, but if you're doing low-level networking stuff and need to make sure your data is in network byte order, use htons and friends. The advantage of using htons and friends is that it is cross-platform, whereas with FlipWord you'd be assuming that host byte order is different than network byte order. I hope I didn't ramble on too much and that some of what I just said made sense :). - sik0fewl 14:12, 16 Jan 2005 (EST)

What about floats and doubles? - Deps 13:35, April 12, 2006 (EDT)

There's no guarantee that the internal representation of a floating point number is the same, even if you do get the endianness right. One possible way is to serialise the mantissa and exponent as separate integral numbers. ( If you have C99 libs, frexp is helpful for this. ) However there are many other methods as well, depending on what the numbers are storing. If you know they're in [0,1], multiplying by std::numeric_limits<unsigned long>::max() and serialising that will often work fine. You could store a unit vector as 2 angles, for example. --Me22 13:43, 12 April 2006 (EDT)