和筆記內容(19)

2020-08-14 01:04:39

chain plugin note

網路位元組序轉化爲本地位元組序,網路位元組序按照大端格式存放

uint32_t ntohl(uint32_t n)

{

union { int i; char c; } u = { 1 };

return u.c ? bswap_32(n) : n;

}

#define bswap_32(x) __bswap_32(x)

static __inline uint32_t __bswap_32(uint32_t __x)

{

return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;

}