Pushok

bit fields

Jun 12th, 2012
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #pragma pack(push, 1)
  4. struct test
  5. {
  6.     bool b1:1;
  7.     bool b2:1;
  8.     bool b3:1;
  9.     bool b4:1;
  10.  
  11.     bool b5:1;
  12.     bool b6:1;
  13.     bool b7:1;
  14.     bool b8:1;
  15. };
  16. #pragma pack(pop)
  17.  
  18. int main()
  19. {
  20.     test t;
  21.  
  22.     *(bool*)(&t) = 0;
  23.  
  24.     t.b1 = 1;
  25.     t.b2 = 0;
  26.     t.b3 = 1;
  27.     t.b4 = 0;
  28.     t.b5 = 1;
  29.     t.b6 = 0;
  30.     t.b7 = 1;
  31.     t.b8 = 0;
  32.  
  33.     std::cout << t.b1 << " " << t.b2 << " " << t.b3 << " " << t.b4;
  34.  
  35.     std::cin.get();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment