convert binary data to int

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Jan 10 05:35:11 EST 2007


At Wednesday 10/1/2007 07:17, rubbishemail at web.de wrote:

>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 




More information about the Python-list mailing list