@staticmethod
#输入一个16进制字符串,转化为ascii码,字母的值按照大写输出
def str2ascii1(string):
asciivalue = ''
try:
for i in range (len(string)):
num = int(string[0],16)
if num > 9:
asciivalue += str(num + 31)
else:
asciivalue += str(num + 30)
string = string[1:]
except Exception, e:
logging.error ('str2ascii error:'+ string)
return asciivalue
@staticmethod
#输入一个16进制字符串,转化为ascii码,字母的值按照大写输出
def str2ascii2(string):
asciivalue = ''
try:
string = string.upper()
for i in range (len(string)):
num = hex(ord(string[0]))[2:]
asciivalue += num
string = string[1:]
except Exception, e:
logging.error ('str2ascii error:'+ string)
return asciivalue
@staticmethod
#输入一个16进制字符串,转化为ascii码,字母的值按照大写输出
def str2ascii3(string):
asciivalue = ''
try:
string = string.upper()
for i in range (len(string)):
num = format(ord(string[0]),'x')
asciivalue += num
string = string[1:]
except Exception, e:
logging.error ('str2ascii error:'+ string)
#输入一个16进制字符串,转化为ascii码,字母的值按照大写输出
def str2ascii1(string):
asciivalue = ''
try:
for i in range (len(string)):
num = int(string[0],16)
if num > 9:
asciivalue += str(num + 31)
else:
asciivalue += str(num + 30)
string = string[1:]
except Exception, e:
logging.error ('str2ascii error:'+ string)
return asciivalue
@staticmethod
#输入一个16进制字符串,转化为ascii码,字母的值按照大写输出
def str2ascii2(string):
asciivalue = ''
try:
string = string.upper()
for i in range (len(string)):
num = hex(ord(string[0]))[2:]
asciivalue += num
string = string[1:]
except Exception, e:
logging.error ('str2ascii error:'+ string)
return asciivalue
@staticmethod
#输入一个16进制字符串,转化为ascii码,字母的值按照大写输出
def str2ascii3(string):
asciivalue = ''
try:
string = string.upper()
for i in range (len(string)):
num = format(ord(string[0]),'x')
asciivalue += num
string = string[1:]
except Exception, e:
logging.error ('str2ascii error:'+ string)
return asciivalue
方式1与3的速度差不多,方式2的速度是1与3的一半多点,大概5.5比8