IamPolaris IamPolaris -4 years ago 132
Python Question

How do I convert a single character into it's hex ascii value in python

I am interested in taking in a single character,

c = 'c' # for example
hex_val_string = char_to_hex_string(c)
print hex_val_string



What is the simplest way of going about this? Any predefined string library stuff?

Answer Source
>>> hex(ord("c"))
>>> format(ord("c"), "x")
>>> "c".encode("hex")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download