I dont understand that question. If you need to send 4 bytes of information then you need 4 bytes of storage. I'm not sure how you expect to get more efficient than that.
Could you please explain a little better what it is you are trying to do?
L7Sqr
Practically a Posting Shark
867 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
A union allows you to have two (or more) members share the same memory. In that manner you will always see a change in the byte array if you modify the bits of the structure. The problem you may run into is packing/padding. For instance given the following structure
struct foo {
unsigned a : 3;
};
it may be the case that sizeof (struct foo) is actually 4 (bytes). That is certainly less efficient that say storing the bits in a char which is 1 byte.
It really boils down to what you want to represent. If you want to store the value of a bitfield in a char variable then you set up a structure with bitfields and padding and use a union with the appropriately sized character buffer. If you want to minimize the space you use when storing your bits then you choose the character array and manage the bit manipulations yourself.
L7Sqr
Practically a Posting Shark
867 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7