I know how to reverse the byte order (convert big endian to little endian in C [without using provided func]) - in this case I'd like to use __builtin_bswap64
I also know how to copy a 64bit uint to a char array - ideally memcopy. (How do I convert a 64bit integer to a char array and back?)
My problem is the combination of both these. At the root of the problem, I'm trying to find a faster alternative to this code:
carr[33] = ((some64bitvalue >> 56) & 0xFF) ;
carr[34] = ((some64bitvalue >> 48) & 0xFF) ;
carr[35] = ((some64bitvalue >> 40) & 0xFF) ;
carr[36] = ((some64bitvalue >> 32) & 0xFF) ;
carr[37] = ((some64bitvalue >> 24) & 0xFF) ;
carr[38] = ((some64bitvalue >> 16) & 0xFF) ;
carr[39] = ((some64bitvalue >> 8) & 0xFF) ;
carr[40] = (some64bitvalue & 0XFF);
As memcopy doesn't take the result of __builtin_bswap64 as source argument (or does it?), I tried this:
*(uint64_t *)upub+33 = __builtin_bswap64(some64bitvalue);
but I end up with the error: lvalue required as left operand of assignment
Is there a faster alternative to the original code I'm trying to replace at all?