[Tutor] Struct the solution for Hex translation

Johan Geldenhuys johan at accesstel.co.za
Mon Feb 19 15:19:28 CET 2007


Hi all,
 
I read in some conversations that the struct module maybe helpful in
converting Hex values to binary or decimal. Maybe I understood it
incorrectly.
 
Here is my problem.
 
I have a 22 byte data packet on a tcp socket connection. My data field is
from the 6th byte to byte 20. 14 bytes in total.
The first two bytes of the data is a 16 bit value. Eg: "\xe2\x01'
 
I can the first byte into binary if I use 'e2', but I don't know how to get
the '\x' out of the first byte to use it in python. My data has the '\x' and
all I need is the 'e2'.
 
Any advice of the usage of the struct module or how I can get rid of the
'\x' in my data?
 
Hopefully I have given enough information.
 
Thanks
 
Johan

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.2/692 - Release Date: 2007/02/18
04:35 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070219/a4dd2d0e/attachment.htm 


More information about the Tutor mailing list