bit parsing from file

Mensanator mensanator at aol.com
Thu May 29 12:26:24 EDT 2008


On May 29, 9:42�am, "rewo... at gmail.com" <rewo... at gmail.com> wrote:
> Hello,
>
> I'm tring to make a cutting script.
> The problem is the following, i have a sample pattern, for
> example :'11101110' (0xEE)
> That is the sign of the data begining.
> How can i cut a file if the byte stepping is not the same, for
> example:
>
> file=open('test.bin','rb')
> data=file.read()
> print binascii.hexlify(data) � � � � � �# BB9A (1011101110011010)
> file.close()
>
> so i need to cut the first two bit and start to writeout the bit
> stream to another file
> If somebody have an idea to do this, please share with me.
> Thanx

Cutting off the leading two bits isn't a problem,
but once you write out the byte 11101110  you are
left with 011010 which cannot be written as it's not
a byte. How do you plan to handle that? Add two bits
at the MSB (00011010) or two bits at the LSB (01101000)
or discard the fractional byte?

And do you always know what the bit offset is or
do you have to search for the 11101110 starting
pattern?

>
> Rew




More information about the Python-list mailing list