我需要从具有以下数据结构(它是12字节结构)的二进制数据文件中找出Epoch时间:
Field-1 : Byte 1, Byte 2, + 6 Bits from Byte 3
Time-1 : 2 Bits from Byte 3 + Byte 4
Time-2 : Byte 5, Byte 6, Byte 7, Byte 8
Field-2 : Byte 9, Byte 10, Byte 11, Byte 12对于字段-1和字段-2,我没有问题,因为它们可以很容易地取出。
我需要在Epoch time (long)中的时间值,因为它以Bytes 5、6、7、8、3和4包装如下:
其余10位时间值以Bytes 3和字节4包装如下:
因此,时间值的总位数是42位,如上面所示。
我需要计算出这42位的历元值。我该怎么做呢?
我做过这样的事情,但不确定它是否给了我正确的价值:
typedef struct P_HEADER {
unsigned int tmuNumber : 22; //sorry for the typo.
unsigned int time1 : 10; // Bits 6,7 from Byte-3 + 8 bits from Byte-4
unsigned int time2 : 32; // 32 bits: Bytes 5,6,7,8
unsigned int traceKey : 32;
} __attribute__((__packed__)) P_HEADER;然后在代码中:
P_HEADER *header1;
//get input string in hexa,etc..etc..
//parse the input with the header as :
header1 = (P_HEADER *)inputBuf;
// then print the header1->time1, header1->time2 ....
long ttime = header1->time1|header1->time2;这就是释放价值观的方法吗?
发布于 2012-03-29 14:41:08
这将为您提供所需的价值:
typedef struct P_HEADER {
unsigned int tmuNumber : 22;
unsigned int time1 : 10; // Bits 6,7 from Byte-3 + 8 bits from Byte-4
unsigned int time2 : 32; // 32 bits: Bytes 5,6,7,8
unsigned int traceKey : 32;
} __attribute__((__packed__)) P_HEADER;
long ttime = ((uint64_t)header1->time1) << 32 | header1->time2;只是在小终端机器上才有这样的效果。
https://stackoverflow.com/questions/9927375
复制相似问题