how to print out each single char from a string in HEX format?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Jun 4 19:46:08 EDT 2007
En Mon, 04 Jun 2007 20:03:39 -0300, mike <needpassion at gmail.com> escribió:
> I've researched python pretty much but still have no idea how to print
> out each single character from a string in HEX format? Hope someone
> can give me some hints. Thanks a lot.
>
> e.g. ###here is a string
>
> a='01234'
>
> ###how to print out it out in this way
>
> 0x31 0x31 0x32 0x33 0x34
py> a='01234'
py> for c in a:
... print "%#x" % ord(c),
...
0x30 0x31 0x32 0x33 0x34
py>
See <http://docs.python.org/lib/built-in-funcs.html#l2h-55> for the ord()
function and <http://docs.python.org/lib/typesseq-strings.html> for the
"%#x" format
--
Gabriel Genellina
More information about the Python-list
mailing list