当我读取二进制文件时,程序会跳过等于 0 的字节。我的程序在 C 中:
int main(int argc, char const *argv[])
{
FILE * input_file = fopen("binary.bin", "rb");
uint32_t b = 0 ;
fread(&b, sizeof(uint32_t) , 1 , input_file);
printf("----- Here are the data stored in the file -----\n");
printf("First uint_32 : %d\n", b);
printf("------------------------------------------------\n");
return 0;
}
输出 :
----- Here are the data stored in the file -----
First uint_32 : 16777216
------------------------------------------------
二进制文件:
xxd -b binary.bin
00000000: 00000000 00000000 00000000 00000001 00000000 00000000 ......
00000006: 00000000 00110010 00000000 00000000 00000000 01100100 .2...d
0000000c: 00000000 00000000 00000000 00010100 00000000 00000000 ......
00000012: 00000000 00000000 00000000 00000000 01011001 00110000 ....Y0
为什么输出不是 1 ?
你得到了16777216
一个输出。
让我们看看它的二进制表示
00000001000000000000000000000000
这是由于数据在内存中的写入方式取决于系统的架构。
这就是系统的字节顺序。你应该阅读little-endian
和big-endian
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句