试图翻一番,从大端到小端。 一条途径是使用
double val, tmp = 5.55;
((unsigned int *)&val)[0] = ntohl(((unsigned int *)&tmp)[1]);
((unsigned int *)&val)[1] = ntohl(((unsigned int *)&tmp)[0]);
但随后我得到警告:“倾斜型旁观器将打破严格的规则”,我无意将这一警告化为乌有。
另一途径是:
#define ntohll(x) ( ( (uint64_t)(ntohl( (uint32_t)((x << 32) >> 32) )) << 32) | ntohl( ((uint32_t)(x >> 32)) ) )
val = (double)bswap_64(unsigned long long(tmp)); //or
val = (double)ntohll(unsigned long long(tmp));
But then a lose the decimals. Anyone know a good way to swap the bits on a double without using a for loop?