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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -