title: Swap bits in c++ for a double
body: <p>Im trying to change from big endian to little endian on a double. One way to go is to use</p>
  
  <pre><code>double val, tmp = 5.55;
  
  ((unsigned int *)&amp;val)[0] = ntohl(((unsigned int *)&amp;tmp)[1]);
  ((unsigned int *)&amp;val)[1] = ntohl(((unsigned int *)&amp;tmp)[0]);
  </code></pre>
  
  <p>But then I get a warning: "dereferencing type-punned pointer will break strict-aliasing rules" and I dont want to turn this warning off.</p>
  
  <p>Another way to go is:</p>
  
  <pre><code>#define ntohll(x) ( ( (uint64_t)(ntohl( (uint32_t)((x &lt;&lt; 32) &gt;&gt; 32) )) &lt;&lt; 32) | ntohl( ((uint32_t)(x &gt;&gt; 32)) ) ) 
  
  val = (double)bswap_64(unsigned long long(tmp)); //or
  val = (double)ntohll(unsigned long long(tmp));
  </code></pre>
  
  <p>But then a lose the decimals.
  Anyone know a good way to swap the bits on a double without using a for loop?</p>