我有一个MATLAB脚本,该脚本调用C代码,该c代码读取我的DAT文件,由我的所有数据组成,其中一个是Timestamp_low。在Windows上运行我的脚本,我获得的正确时间值为4.1472*10^9,但是Linux/Mac我获得了1.8447*10^19的值。本质上,我只从文件中读取并保存它。
unsigned int timestamp_low = inBytes[0] + (inBytes[1] << 8) +
(inBytes[2] << 16) + (inBytes[3] << 24);
mxSetField(outCell, 0, "timestamp_low", mxCreateDoubleScalar((double)timestamp_low));
有人知道MEX兼职器在此类内容上的不同OS上是否有不同的作用?我本人还没有编写此代码,所以我对细节并不非常熟悉。我用它从WiFi设备收集CSI。我已经尝试使用不同的MATLAB版本和Mac/Linux,它们产生相同的(错误(值。
我怀疑您在这里有一些不确定的行为:
unsigned int timestamp_low = inBytes[0] + (inBytes[1] << 8) +
(inBytes[2] << 16) + (inBytes[3] << 24);
(尽管您还没有告诉我们inBytes
的类型尚不清楚(。
尝试:
unsigned int timestamp_low = (unsigned int)inBytes[0] + ((unsigned int)inBytes[1] << 8) +
((unsigned int)inBytes[2] << 16) + ((unsigned int)inBytes[3] << 24);