title: How do you write (portably) reverse network byte order?
body: <p><em>Background</em></p>
  
  <p>When designing binary file formats, it's generally recommended to write integers in network byte order. For that, there are macros like <code>htonhl()</code>. But for a format such as WAV, actually the little endian format is used.</p>
  
  <p><em>Question</em></p>
  
  <p><strong>How do you portably write little endian values, regardless of if the CPU your code runs on is a big endian or little endian architecture?</strong> (Ideas: can the standard macros <code>ntohl()</code> and <code>htonl()</code> be used "in reverse" somehow? Or should the code just test runtime if it's running on a little or big endian CPU and choose the appropriate code path?)</p>
  
  <p><sub>So the question is not really about file formats, file formats were just an example. It could be any kind of serialization where little endian "on the wire" is required, such as a (heretic) network protocol.</sub></p>