Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 16th, 2012  |  syntax: None  |  size: 1.24 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. To Obtain EPOCH Time Value from a Packed BIT Structure in C
  2. Field-1 : Byte 1, Byte 2, + 6 Bits from Byte 3
  3. Time-1  :                   2 Bits from Byte 3 + Byte 4
  4. Time-2  : Byte 5, Byte 6, Byte 7, Byte 8
  5. Field-2 : Byte 9, Byte 10, Byte 11, Byte 12
  6.        
  7. typedef struct P_HEADER {
  8.     unsigned int tmuNumber : 22; //sorry for the typo.
  9.     unsigned int time1 : 10; // Bits 6,7 from Byte-3 + 8 bits from Byte-4
  10.     unsigned int time2 : 32; // 32 bits: Bytes 5,6,7,8
  11.     unsigned int traceKey : 32;
  12. } __attribute__((__packed__)) P_HEADER;
  13.        
  14. P_HEADER *header1;
  15.  
  16. //get input string in hexa,etc..etc..
  17. //parse the input with the header as :
  18. header1 = (P_HEADER *)inputBuf;
  19. // then print the header1->time1, header1->time2 ....
  20. long ttime = header1->time1|header1->time2;
  21.        
  22. typedef struct P_HEADER {
  23.     unsigned int tmuNumber : 22;
  24.     unsigned int time1 : 10; // Bits 6,7 from Byte-3 + 8 bits from Byte-4
  25.     unsigned int time2 : 32; // 32 bits: Bytes 5,6,7,8
  26.     unsigned int traceKey : 32;
  27. } __attribute__((__packed__)) P_HEADER;
  28.  
  29. long ttime = ((uint64_t)header1->time1) << 32 | header1->time2;
  30.        
  31. typedef struct P_HEADER {
  32.     unsigned int field1      : 22;
  33.     unsigned long long time  : 42;
  34.     unsigned int field2;
  35. } __attribute__((__packed__)) P_HEADER;