fork download
  1. #include <cstdio>
  2. #include <cstdint>
  3.  
  4. struct test16 {
  5. uint16_t x:12;
  6. uint16_t y:12;
  7. };
  8.  
  9. struct test32 {
  10. uint32_t x:12;
  11. uint32_t y:12;
  12. };
  13.  
  14. int main() {
  15. test16 t16; t16.x=0xABC; t16.y=0xDEF;
  16. test32 t32; t32.x=0x123; t32.y=0x456;
  17.  
  18. printf("%u %u\n", sizeof (test16), sizeof (test32));
  19. printf("%0.3X %0.3X %0.8X\n", t16.x, t16.y, t16);
  20. printf("%0.3X %0.3X %0.8X\n", t32.x, t32.y, t32);
  21. return 0;
  22. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
4 4
ABC DEF 0DEF0ABC
123 456 00456123