
Untitled
By: a guest on
Apr 16th, 2012 | syntax:
None | size: 1.24 KB | hits: 8 | expires: Never
To Obtain EPOCH Time Value from a Packed BIT Structure in C
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
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;
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;
typedef struct P_HEADER {
unsigned int field1 : 22;
unsigned long long time : 42;
unsigned int field2;
} __attribute__((__packed__)) P_HEADER;