我有一个文件,我将它读入到一个字符数组中。
现在,如果我知道文件在位置0x8处以little endian格式存储了一个32位整数,那么我该如何从字符数组中检索它呢?
FILE * file = fopen("file");
char buffer[size];
fread(buffer,1,size,file);
int = buffer[0x8]; // What should I do here?
// I imagine it involves some strange pointer
// arithmetic but I can't see what I should do,
// casting to int just takes the first byte,
// casting to (int *) doesn't compile
*((int*)(buffer + 8))
是相同的。很可能你的机器是little-endian架构——英特尔或 AMD... - LihO