Re: Binary handling
From: Diez B. Roggisch (deetsNOSPAM_at_web.de)
Date: 05/17/04
- Next message: Peter Hansen: "Re: [PYGTK] Insert Backspace into text widget?"
- Previous message: Peter Hansen: "Re: NIC adress of incoming socket."
- In reply to: Derfel: "Binary handling"
- Next in thread: Miki Tebeka: "Re: Binary handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 May 2004 14:24:40 +0200
Derfel wrote:
> Hello all,
> I have a file of binary data. I want to read this file and parse the data
> in it. The format of the file is:
> 8 bits number of data pakets
> 6 bits offset
> 20 bits time
> 8 states
>
> How can I read this fields in binary? I see the struct module and the
> binascii, but I can't split the diferent fiels.
You can use struct to create a long from your data and then work on that
with the usual bitwise operators for shift and boolean and so that you
extract the actual data. If the above is the entire spec, I see some
problems to get the alignment proper, but with a bit of shifting you should
be able to work around that.
-- Regards, Diez B. Roggisch
- Next message: Peter Hansen: "Re: [PYGTK] Insert Backspace into text widget?"
- Previous message: Peter Hansen: "Re: NIC adress of incoming socket."
- In reply to: Derfel: "Binary handling"
- Next in thread: Miki Tebeka: "Re: Binary handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|