# Host and Network Byte Order for Floats

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

## Recommended Posts

I asked this as a follow-up question to a topic in "For Beginners," but because it is more specific to network programming, I decided to briefly ask here instead: When sending floats over a TCP connection, assuming that I'm not interested in packing the floats into a size less than 4 bytes (as described in the multiplayer forum FAQ), would I have to worry about endianness issues? Or is host and network byte order not an issue for floats? If it is, how would I handle this issue? I cannot find an equivalent of the htonl()/ntohl() functions for floats: only for shorts and longs, i.e., 16-bit and 32-bit integers. Do I have to do it manually? (If so, how would I detect the endianness of the machine the program is running on?) -Gauvir_Mucca

##### Share on other sites
Endianness does matter for floats. Since a float is a 32-bit quantity, you can use htonl/ntohl to do the conversion, something like:
float a;long convertedFloat = htonl(*reinterpret_cast<long *>(&a));