我目前正在处理一些二进制数据。 为了检查和调试应用程序以前生成的数据,我使用 hexdump,但遇到了 hexdump 似乎无法提取 64 位整数字段的障碍。 给定以下最小化示例:
#include <iostream>
#include <fstream>
#include <cstdint>
int main(int argc, char** argv){
std::ofstream os("tmp.bin", std::ios::out | std::ios::binary);
uint64_t x = 7;
os.write((char*)&x,sizeof(uint64_t));
os.close();
return 0;
}
我在系统上执行了一个简单的十六进制转储:
hexdump tmp.bin
> 0000000: 0007 0000 0000 0000
> 0000008:
现在尝试提取64位宽度的无符号整数产生了以下结果:
hexdump -e '/8 "%u"' tmp.bin
> hexdump: bad byte count for conversion character u
根据由 David Mair 撰写的 hexdump 手册,应该可以做到这一点,但我没有成功。我错过了什么?