ASCII to HEX conversion

Noah noah at noah.org
Fri Apr 12 02:29:32 EDT 2002


Hex should work. What's the problem with it?
What you also need is ord() to convert a string character
into a number. Try this:
	ASCII = 'A'
	HEX = hex ( ord(ASCII) )
	print HEX
	# If you don't want the "0x" 
	# at the beginning then just clip it off:
	print HEX[2:]

Yours,
Noah

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Matt
Sent: Thursday, April 11, 2002 3:16 PM
To: python-list at python.org
Subject: ASCII to HEX conversion


I need to write a program that converts ASCII test into the
hexidecimal equivalent.  It would help if it could convert to binary,
too.

Example:

ASCII = "A"
HEX = 41

I tried using the hex() function, but it does not work.  If anyone
could tell me how to do this without making a lookup table of all the
ASCII values.


Matt Leisinger
leisinmr at purdue.edu






More information about the Python-list mailing list