String to hexadecimal conversion
Steve Holden
steve at holdenweb.com
Fri Sep 12 08:36:37 EDT 2008
Praveena P wrote:
> Hi folks,
>
> I am new to Python... so am not too sure about how the type conversion
> works.
>
> 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?
Generally speaking, reading a file 2 bytes at a time i going to be
inefficient and untidy.
Does this help?
>>> int("00000000000020E0000032F800000000400022005E", 16)
170696759285949896156423472451551326L
>>>
Or have I misunderstood your intention?
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list