Converting Hex to decimal

Miki Tebeka miki.tebeka at zoran.com
Tue Jun 1 06:50:30 EDT 2004


Hello Dean,

> I have a file containing hex data. I would like to convert the
> contents of the file to decimal by reading each by sequentially (one
> byte at the time). Is there a module that has such functionality or
> does someone have the relevant code?
Have a look at `array' or `struct' modules.
If you just want to read "raw" bytes you can do:
for c in open("some_file").read():
    print hex(ord(c))
(Note that this read *all* the file into memory)

HTH.
--
-------------------------------------------------------------------------
Miki Tebeka <miki.tebeka at zoran.com>
http://tebeka.web1000.com
The only difference between children and adults is the price of the toys.




More information about the Python-list mailing list