I am working with a binary file and I have 8 bytes that I want to convert to an integer.
This way works:
But it's not very elegant. Is there any elegant way to convert 8 bytes to an integer.
This way works:
Code:
unsigned char buf[1024];
long long value;
value = ((long long)buf[0]<<56) | ((long long)buf[1]<<48) | ((long long)buf[2]<<40) | ((long long)buf[3]<<32) | (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
printf("%lld\n", value);
Comment