How do I read multipli bytes from file?
Siggy Brentrup
bsb at winnegan.de
Sun Dec 19 09:44:17 EST 1999
"Jens Arnfelt" <jens.arnfelt at get2net.dk> writes:
> Hi There !
>
> I have been working on an python program that reads Call Data Records from a
> file!
>
> Ex. the following values in hex (a telephone number encoded in BCD(Binary
> Coded Dicimal) :
>
> 45 26 10 05 01 1f ff ff ff ff
>
> The length of the fiels is 10 bytes.
> I need to convert this into somthing readable in a single string. The result
> should be!
>
> '45261005011fffffff'
>
> I've tryed with the string.unpack() but its return a list of bytes, not a
> string.
>
> Any help would apriciated
It's not very efficient but it works for getting at the nibbles:
string.join(map(lambda b:'%02x' % (b&0xff), LIST_OF_INTS)
Further tweaking may be required depending on the exact representation
of phone numbers in your input data.
HIH
Siggy
--
Siggy Brentrup - bsb at winnegan.de - http://www.winnegan.de/
****** ceterum censeo javascriptum esse restrictam *******
More information about the Python-list
mailing list