【发布时间】:2013-12-06 18:51:39
【问题描述】:
我尝试从二进制文件中读取一个以 4 个字节编码的日期(大端序)。
我愿意:
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));
但我明白了:
Thu Jan 1 00:59:27 1970
我的代码有什么问题?谢谢。
【问题讨论】:
-
你的系统是小端吗?
-
OT:
sizeof(char)根据定义等于 1。
标签: c date gcc compiler-construction endianness