본문 바로가기

Study/Useful Source Codes

Python, String to Hex (String->Hex)

# Convert String to Hex

def toHex(str):

result = []

for character in str:

hv = hex(ord(character)).replace('0x','')

result.append('%'+hv)

return reduce(lambda x,y:x+y,result)