Assuming the buffer inputsaved the data in a small endian view , which means that the least significant byte is at the lowest address and the highest byte at the highest address, you can do something like the following.
#include <stdio.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
int main(void)
{
int i;
unsigned char input[8] = {0x01, 0x02, 0x03, 0x04, 0x5, 0x06, 0x07, 0x08 };
uint64_t paquet = 0;
for( i = 7; i >= 0; --i )
{
paquet <<= 8;
paquet |= (uint64_t)input[i];
}
printf("0x%" PRIx64 "\n", paquet);
return 0;
}
You can see a working example of ideone .
If the buffer is stored in large end mode, then the reverse cycle.
Thanks to m24p for pointing out the error in my original project.
Jimbo source
share