I have a date encoded (big endian) in 4 bytes that I'm trying to read from a binary file.
I do:
char date[4];
long seconds;
s = read(fd, date, sizeof(char) * 4);
seconds = (date[3]<<0) | (date[2]<<8) | (date[1]<<16) | (date[0]<<32);
printf("%s\n", ctime(&seconds));
But I get:
Thu Jan 1 00:59:27 1970
What's wrong with my code ? Thanks.
(date[0]<<32);
looks wrong. 16 + 8
is 24
not 32
.