I\'m trying to find a way to print a string in hexadecimal. For example, I have this string which I then convert to its hexadecimal value.
my_string = \"deadbeef
Use
print " ".join("0x%s"%my_string[i:i+2] for i in range(0, len(my_string), 2))
like this:
>>> my_string = "deadbeef"
>>> print " ".join("0x%s"%my_string[i:i+2] for i in range(0, len(my_string), 2))
0xde 0xad 0xbe 0xef
>>>
On an unrelated side note ... using string as a variable name even as an example variable name is very bad practice.