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


output:

63


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

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