On Sat, Jun 15, 2013 at 10:35 PM, Benjamin Schollnick <benja...@schollnick.net> wrote: > 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 > > > > -- > http://mail.python.org/mailman/listinfo/python-list >
Better: a programmer should know how to convert hexadecimal to decimal. 0x1B = (0x1 * 16^1) + (0xB * 16^0) = (1 * 16) + (11 * 1) = 16 + 11 = 27 It’s that easy, and a programmer should be able to do that in their brain, at least with small numbers. Or at least know that: http://lmgtfy.com/?q=0x1B+in+decimal Or at least `hex(27)`; or '`{:X}'.format(27)`; or `'%X' % 27`. (I despise hex numbers with lowercase letters, but that’s my personal opinion.) -- Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html -- http://mail.python.org/mailman/listinfo/python-list