Sign in to follow this  

bit stream to structure

This topic is 1910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I am wondering what the best practice is for placing a series of bits and bytes read in from a file/external source into a packed structure.

For example the program header from an mpeg stream:

00 00 01 BA 7F FF FF 8A D4 01 86 66 CF F8

Should fill these variables in my packed structure:
uint32 sync_bytes;
unsigned mask1 : 2;
unsigned system_clock_ref1 : 3;
unsigned mask2 : 1;
unsigned system_clock_ref2 : 15;
unsigned mask3 : 1;
unsigned system_clock_ref3 : 15;
unsigned mask4 : 1;
unsigned system_ext : 9;
unsigned mask5 : 1;
unsigned mux_rate : 22;
unsigned mask6 : 2;
unsigned reserved : 5;
unsigned stuffing_length : 3;

The masks should be like the purple values shown here: [url=""][/url]

I think I am going wrong with the endianness of the system.

I have also thought about serialisation of the data and literally stepping through each bit, this seems overly cautious and slow.

I'd be happy to hear any thoughts on this.

Thanks in advance.


Share this post

Link to post
Share on other sites
Sign in to follow this