Getting hex value of a character
Aaron K. Johnson
akjmicro at yahoo.com
Thu Dec 12 12:34:15 EST 2002
In message <1s3K9.1304$0V.71588928 at newssvr14.news.prodigy.com>, "Dennis
Reinhardt" wrote:
> I am trying to print the hexadecimal value of a string. In other words, the
> string "AB" would print as "4142". I simply cannot get the formatting
> right. Here is a test case:
>
> rawg = "g"
> print "hex = %02x" % rawg
> print "hex = %02x" % int(rawg)
> print "hex = %02x" % string.atoi(rawg)
> print "hex = %02x" % struct.unpack("c", rawg)
> print "hex = %02x" % int(struct.unpack("c", rawg))
>
> None of the print statements I have tried above work. A common problem to
> many is that int cannot convert the argument given. The result I am hoping
> for here is "hex = 67". This must be really simple but I am not getting it
> and have consulted the indexes of 4 Python books.
>
> --
>
> Dennis Reinhardt
>
> http://www.dair.com
hex(org('g')) will print '0x67'....will that do?
-Aaron.
More information about the Python-list
mailing list