Advertisement
Guest User

What is happening?

a guest
Sep 13th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. int main()
  2. {
  3.     struct Bits
  4.     {
  5.         unsigned a : 1, b : 3, c : 4,       // struct of bit-fields to hold
  6.                  d : 5, e : 4, f : 4,       // the different number of bits
  7.                  g : 4, h : 4, i : 4,
  8.                  j : 5, k : 2;
  9.     };
  10.  
  11.     union Bitvalue                          // union to hold bits and value
  12.     {
  13.         Bits bits;                          // struct of bit-fields
  14.         size_t value;                       // variable to extract value
  15.     };
  16.  
  17.         // define a union with the values supplied in the exercise manual
  18.     Bitvalue bitvalue = {{0, 7, 15, 10, 6, 7, 15, 15, 7, 0, 3}};
  19.     bitset<48> allbits(bitvalue.value);
  20.  
  21.     cout << allbits << '\n'; // should print 000000001100000011111111111011101100101011111110‬
  22.                              // but prints   000001100000011100011111111011101100101011111110
  23.                              // note the extra 000           ^^^ here
  24.                              // otherwise the sequence is correct, it just adds 3 extra 0 bits
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement