fork(5) download
  1. #include <cstdint>
  2. #include <iostream>
  3.  
  4. using byte = std::uint8_t;
  5.  
  6. struct Regs
  7. {
  8. union
  9. {
  10. std::uint16_t bc;
  11.  
  12. struct
  13. {
  14. // The order of these bytes matters
  15. byte c;
  16. byte b;
  17. };
  18. };
  19. };
  20.  
  21. int main()
  22. {
  23. Regs regs;
  24.  
  25. regs.b = 1; // 0000 0001
  26. regs.c = 7; // 0000 0111
  27.  
  28. // Read these vertically to know the value associated with each bit
  29. //
  30. // 2 1
  31. // 5 2631
  32. // 6 8426 8421
  33. //
  34. // 256 + 4 + 2 + 1 = 263
  35. //
  36. // The overall binary: 0000 0001 0000 0111
  37.  
  38. std::cout << regs.bc << "\n";
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
263