1.写脚本过程中经常遇到字符串和16进制直接的互相转换:现在用python 实现字符串到16进制的整数的转换脚本。
//-----代码如下:
str = "11223344556677889900AABBCCDDEEFF" strLen = len(str) print("字符串长度值为(字符个数):",strLen) intC = 0 intHexV = 0; for i in range(0,strLen): c = str[i:i+1] if c == 'A': intC = 10 elif c == 'B': intC = 11 elif c == 'C': intC = 12 elif c == 'D': intC = 13 elif c == 'E': intC = 14 elif c == 'F': intC = 15 else: intC = int(c) intHexV *= 16 intHexV += intC print("16进制值为 = ",hex(intHexV))
//-----代码结束------------------------------------
输出结果为:16进制值为 = 0x11223344556677889900aabbccddeeff