C++ htonll and back -
i have found following code capable of converting int64_t network byte order. need opposite code, such network byte order converted little endian machine. code this.
int64_t decode(void* value){ int64_t vv = *((int64_t*) value); int num = 42; if(*(char *)&num == 42) //test big/little endian return (((uint64)htonl(vv)) << 32) + htonl(vv >> 32); else return vv; }
thanks lot!
the code htonll
#define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl((x) >> 32))
flips bytes end end. if apply twice, restores value original state. same function can used ntohll
.
Comments
Post a Comment