• Advertisement
Sign in to follow this  

SDL_net float network byte order

This topic is 3795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to convert a float to network byte order? I've searched around and it seems that float to NBO is a big problem. Is there a fix for it? or maybe some other function I haven't heard of?

Share this post


Link to post
Share on other sites
Advertisement
I think you just have to do a dynamic cast to the equivalent int size and then use the SDL macros to change it the rest of the way.

Share this post


Link to post
Share on other sites
actually i figured it out yesterday...

I have to reinterpret_cast (so the bytes aren't switched).

// write a float
float myF;
SDLnet_Write32(pData,*reinterpret_cast<long*>(&myF));

// read a float
float myF;
long temp;
temp = SDLnet_Read32(pData);
myF = *reinterpret_cast<float *>(&temp);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement