Endianness Agnostic ntoh
- POST
From the Endianness detection blog entry, we have learned how to do that using predefined macros across different architectures. Our next task is to write ntoh (network to host) and hton (host to network) functions to convert integers and floating point values between network and host formats. Here’s a catch: Do not use conditionals - basically, do not use any of the keywords if/else/for/while. To make it even harder: Do not include any headers and also do not use #if/#else/#endif pre-processors.