He cannot have it both ways. You cannot just keep track of values spread over random number of bits, then expect to get it back in the same manner.
Actually, with my example, you can. If you want the original input, you display using:
union x somevar;
somevar.b[0] ... b[3]
If you want the data as it is spread out over the bit fields, you do it:
somevar.a.a ... somevar.a.d
You cannot, I repeat cannot simply have both worlds with a single variable, unless you use a union.
You cannot mash your data acroass a bitfield (which has different bit alignments than your original data) and expect to just fetch it back into it's original form with simple printing operators.
The only, and best, way to do this, is a union as I have shown.
I'm not harping at you, I'm letting him know that you cannot simply mash your stuff into a bitfield and then wonder why "it doesn't print right!".
And actually, to quote the original post:
It does sound like he just wants it hammered into a bit field, so he can then just display the bitfield (not the original data--he says nowhere that he wants to print its original form!).How do I write a structure that will retreive information from this array in the following manner -->
the first three bits contain information a
the next 5 bits contain information b
the next 12 bits contain information c
the next 12 bits contain information d
As such, memcopy would be fine. If he doesn't need to preserve the original data, and just wants to stick it into a bitfield, the union works, memcopy works, etc.
However, if he decides he needs to see the original data, the union is the best bet. (Plus it's easy.)
Quzah.