[Tutor] Will someone please tell me how to read this?

Alan G alan.gauld at freenet.co.uk
Tue Aug 23 00:09:48 CEST 2005

> Is there a name for this type of number?  I'm assuming the \x means 
> it's hex, but then you have things like \x00h, and \x007p^.

It's a sequence of bytes and you've asked Python to print its 
string representation.  So where the bytes are unprintable 
ascii codes it shows you the hex, thus:


Those are all single bytes in hex


that byte has the ascii value for the letter 'h'
(ie. its 104 in decimal)


More bytes as hex


The three ascii characters '7','p','^' 
(or 55,112,94 in decimal)


More hex bytes


'7' again


more bytes as hex... you get the idea?

However that doesn't mean that those are really what the 
data represents. The first 4 bytes could be a 32 bit integer, 
or a short floating point value.

Similary the 7p^ sequence could be three bytes from within an 
integer too.

You really need to know whats being thrown at you down the socket 
otherwise you have very little hope of accurately decoding it.
And to decode it you need to use the struct module.


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list