String to hexadecimal conversion
imageguy1206 at gmail.com
Fri Sep 12 16:41:57 EDT 2008
On Sep 8, 5:05 am, Praveena P <praveenapa... at gmail.com> wrote:
> Hi folks,
> I am new to Python... so am not too sure about how the type conversion
> I have to read a file that contains hexadecimal data and use the data
> further to do some arithmetic calculations.
> A sample of the input is : 00000000000020E0000032F800000000400022005E
> The problem I am facing is this:
> I am using f.read(2) to read a byte at a time, but the data that is
> read is a string rather than a number. So it kind of hampers any
> arithmetic operations I perform on this data...
> Could you please suggest some method I could use for this?
> Thanks guys!
check out the "struct" module in the standard python library.
It's title says it all "Interpreting strings as packed binary data".
I used this extensively to reverse engineer a couple proprietary file
You can read large chucks of the file - perhaps a record ? - and then
based on the format provided, convert it to a tuple.
More information about the Python-list