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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -