An implementation of ntohf() with code

I am working on extracting data from some binary navigation messages today. Working with binary data can be difficult and quite confusing – especially when converting byte order from network (big endian) to host byte order (possibly little endian). The integer types are well covered by ntohs() and ntohl() et al. but when dealing with floats things can get a bit harder as ntohf() isn’t always available to the hard pressed programmer!

So I have included a simple implementation below, I have tested it during my own use, but it use at your own risk as this code may well be an example of a rather dubious use of unions!

This version is slightly adapted from an original implementation by Kevin Bowling (pls. see copyright notice).

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *