Converting Hex to decimal

Peter Hansen peter at engcorp.com
Wed Jun 2 13:42:13 CEST 2004


dean wrote:

> Thanks for your responses so far. I have not been clear it seems so
> here it goes:

Judging by the subsequent responses, you're still not being
clear. :-)

> The file is binary. 

In other words, it is *not* "hex".  It's binary.  Plain and simple.
Is that true?

> Using the standard hpux or linux hexdump (xxd or
> xd) this is the output that is obtained:

So the only hex thing about it is that you can display the contents
using a program that displays binary content as hex?

> 0000000: 5c1a 0100 0100 ff35 0399 7272 9903 0002  \......5..rr....
> 0000010: 010e 0300 050a 0214 ffff ffff 5cd4 2e01  ............\...

But the actual file that you have is the original, binary
file, right?  Not just this hexdump output?

> Each hex character is 8 bits. 

Do you mean that each byte is 8 bits?

> I would like to convert one byte at the
> time and pipe the converted data into a new file.

Convert in what way?  Or do you really mean that you have only
the hexdump output and want to convert it back to the raw binary
file from which it was originally generated, as the last several
respondents have assumed?

Otherwise, it really sounds like you just want to read the file
byte-by-byte and "convert" the bytes in some way, writing them
to a new file.  There is nothing special about doing this: you
would just use open() and .read() and .write() like with any
other file.

-Peter



More information about the Python-list mailing list