代码:
s64 end_time;
struct timespec ts;
getrawmonotonic(&ts);
end_time = timespec_to_ns(&ts);
如何删除 end_time 中的前三个字节和最后一个字节?我想将它存储在 uint32 中。有人可以告诉我该怎么做吗??
uint32 latency;
fscanf(fp, "%lu\n", latency); //fp is reading the end_time and storing in latency.
latency = (uint32) (latency >> 8) & 0xFFFFFFFF;
从 uint32 读取 s64 值后。我只从中读取了 4 个字节。 是否可以从 uint32 读取 s64 ??
最佳答案
这一行有很多错误:
fscanf(fp, "%lu\n", latency);
- 应该是
&latency
(您的版本是一个可崩溃的逻辑错误) uint32 延迟
不一定是unsigned long
我假设您想要将一个数字读入您希望适合 uint32 的延迟?
执行此操作的唯一可移植方法是使用 ifstream。
这是因为 istream 的运算符 >> 将为非标准 uint32 正确重载。
这样做:
std::ifstream myfile("file_containing_values.txt");
uint32 latency;
myfile >> latency; // correct overload is selected by the compiler.
关于c++ - 是否可以从 uint32 读取 s64 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23610033/