fork download
  1.  
  2. #include <stdio.h>
  3. #include <stdint.h>
  4.  
  5. struct __attribute__((packed)) cg_api_packet_header {
  6.  
  7. /// The API version (1 - 15; 4 bits).
  8. uint32_t version : 4;
  9.  
  10. /// Whether the packet carries error information (1 bit).
  11. uint32_t error_flag : 1;
  12.  
  13. /// The payload size (0 - 2047; 11 bits).
  14. uint32_t payload_size : 11;
  15.  
  16. /// The message identifier (0 - 16383; 14 bits).
  17. uint32_t message_id : 14;
  18.  
  19. /// The timestamp in milliseconds (0 - 999; 10 bits).
  20. uint32_t timestamp_milliseconds : 10;
  21.  
  22. /// The timestamp in seconds (32 bits).
  23. uint32_t timestamp_seconds : 32;
  24.  
  25. };
  26.  
  27. int main(void) {
  28.  
  29. struct cg_api_packet_header header = {
  30. .version = 4,
  31. .error_flag = 1,
  32. .payload_size = 123,
  33. .message_id = 247,
  34. .timestamp_milliseconds = 0,
  35. .timestamp_seconds = 111,
  36. };
  37.  
  38. uint8_t* ptr = (uint8_t*)(&header);
  39.  
  40. printf("%02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8]);
  41.  
  42. }
  43.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
74 0F F7 00 00 6F 00 00 00