- Int to Hex
hex(97) # '0x61'
- Int to Char
chr(97) # 'a'
- Int to String
str(97) # '97'
- Hex to int
int('0x61', 16) # 97
- Hex to Char
chr(int('0x61', 16)) # 'a'
- Hex to String
string = '61626364'
''.join(chr(int(string[i:i+2], 16)) for i in range(0, len(string), 2)) # 'abcd' - Char to Int
ord('a') # 97
- Char to Hex
hex(ord('a')) # '0x61'
- String to Int
int('97') # 97
- String to Hex
string = 'abcd'
''.join([hex(ord(x))[2:] for x in string]) # '61626364'
2 則留言:
謝謝,非常實用!!
特別是由string轉hex
張貼留言