Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- struct Bits
- {
- unsigned a : 1, b : 3, c : 4, // struct of bit-fields to hold
- d : 5, e : 4, f : 4, // the different number of bits
- g : 4, h : 4, i : 4,
- j : 5, k : 2;
- };
- union Bitvalue // union to hold bits and value
- {
- Bits bits; // struct of bit-fields
- size_t value; // variable to extract value
- };
- // define a union with the values supplied in the exercise manual
- Bitvalue bitvalue = {{0, 7, 15, 10, 6, 7, 15, 15, 7, 0, 3}};
- bitset<48> allbits(bitvalue.value);
- cout << allbits << '\n'; // should print 000000001100000011111111111011101100101011111110
- // but prints 000001100000011100011111111011101100101011111110
- // note the extra 000 ^^^ here
- // otherwise the sequence is correct, it just adds 3 extra 0 bits
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement