Reading a binary file
Anand Pillai
pythonguy at Hotpop.com
Thu Jun 26 11:48:33 EDT 2003
You need to convert the hex to int with radix 16.
c='a'
h=binascii.hexlify(c)
d=int(h, 16)
Anand Pillai
Sorin Marti <mas at semafor.ch> wrote in message news:<mailman.1056620083.21078.python-list at python.org>...
> Hi Andrew,
>
> Thanks for your answer!
>
> Andrew Bennetts wrote:
> > On Thu, Jun 26, 2003 at 10:01:06AM +0200, Sorin Marti wrote:
> >
> >>But now I need the hex values of the binary file.
> >
> > You can get the hex value of a 1-character string with hex(ord(char)), e.g.:
> >
> > >>> char = 'a'
> > >>> hex(ord(char))
> > '0x61'
> >
>
> That is not exactly what I meant. I've found a solution (a is the binary
> data):
>
> b = binascii.hexlify(a)
>
> For example it gives me C8 which is a HEX-Value. How to change this one
> into a decimal? (The decimal should be 130, right?)
>
> Thanks in advance
>
> Sorin
More information about the Python-list
mailing list