convert binary data to int

R

rubbishemail

Hello,


I need to convert a 3 byte binary string like
"\x41\x00\x00" to 3 int values ( (65,0,0) in this case).
The string might contain characters not escaped with a \x, like
"A\x00\x00"


Any ideas?


Daniel
 
G

Gabriel Genellina

At said:
I need to convert a 3 byte binary string like
"\x41\x00\x00" to 3 int values ( (65,0,0) in this case).
The string might contain characters not escaped with a \x, like
"A\x00\x00"

py> [ord(x) for x in "\x41\x00\x00"]
[65, 0, 0]
py> [ord(x) for x in "A\x00\x00"]
[65, 0, 0]
py> "\x41\x00\x00" == "A\x00\x00"
True
py> "\x41\x00\x00" is "A\x00\x00"
True

(The last test is actually irrelevant, however)


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top