A few questiosn about encoding

Benjamin Schollnick benjamin at schollnick.net
Sat Jun 15 16:35:48 EDT 2013


Nick,

>> The only thing that i didn't understood is this line.
>> First please tell me what is a byte value
>> 
>>> \x1b is a sequence you find inside strings (and "byte" strings, the
>>> b'...' format).
>> 
>> \x1b is a character(ESC) represented in hex format
>> 
>> b'\x1b' is a byte object that represents what?
>> 
>> 
>> >>> chr(27).encode('utf-8')
>> b'\x1b'
>> 
>> >>> b'\x1b'.decode('utf-8')
>> '\x1b'
>> 
>> After decoding it gives the char ESC in hex format
>> Shouldn't it result in value 27 which is the ordinal of ESC ?

I'm sorry are you not listening?

1b is a HEXADECIMAL Number.  As a so-called programmer, did you seriously not consider that?

Try this:

1) Open a Web browser
2) Go to Google.com
3) Type in "Hex 1B" 
4) Click on the first link
5) In the Hexadecimal column find 1B.

Or open your favorite calculator, and convert Hexadecimal 1B to Decimal (Base 10).

		- Benjamin


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130615/a9de4528/attachment.html>


More information about the Python-list mailing list