我有这样的东西。
char header[4096]; //header information from a file
有一个字段称为startByteOffset
which is 8 bytes
(offset in header is 8) 然后还有endByteOffset
which is 8 bytes
in lenght. (offset in header is 16). 我需要更改endByteOffset
. 怎么做?谢谢。如果还不够清楚,请告诉我。
要将整数分解为字符(字节),您可以使用移位和屏蔽。
uint64_t value = /* ... */;
header[endbyteoffset] = value & 0xff;
header[endbyteoffset+1] = (value >> 8) & 0xff;
header[endbyteoffset+2] = (value >> 16) & 0xff;
header[endbyteoffset+3] = (value >> 24) & 0xff;
// ...
header[endbyteoffset+7] = (value >> 56) & 0xff;
您需要知道这些值是以小端还是大端的顺序存储的。我上面提供的示例是针对小端的;对于big-endian,您只需颠倒班次的顺序,首先从最大班次开始。