#include "big_endian.h" void to_big_endian(uint64_t num, unsigned char *result) { *(result+0) = (num >> 56) & 0xff; *(result+1) = (num >> 48) & 0xff; *(result+2) = (num >> 40) & 0xff; *(result+3) = (num >> 32) & 0xff; *(result+4) = (num >> 24) & 0xff; *(result+5) = (num >> 16) & 0xff; *(result+6) = (num >> 8) & 0xff; *(result+7) = (num >> 0) & 0xff; } uint64_t from_big_endian(unsigned char *num) { uint64_t result = ((uint64_t) (*num) << 56); result += ((uint64_t) (*(num+1)) << 48); result += ((uint64_t) (*(num+2)) << 40); result += ((uint64_t) (*(num+3)) << 32); result += ((uint64_t) (*(num+4)) << 24); result += ((uint64_t) (*(num+5)) << 16); result += ((uint64_t) (*(num+6)) << 8); result += ((uint64_t) (*(num+7)) << 0); return result; }