小端序str → 大端序str
一般是为了打印日志自己看着方便
def Little2Big(strLittle):
lenStr = len(strLittle)
time = int(lenStr/2)
j = 0
strBig = ''
for i in range(time):
str = strLittle[lenStr-2-j : lenStr-j]
j += 2
strBig += str
return strBig
def Little2Big(strLittle):
strBig = (int(strLittle, 16).to_bytes(4, 'little')).hex()[:6].upper()
return strBig
import binascii
def Little2Big(strLittle):
return int(strLittle, 16).to_bytes(4, 'little')
def Bytes2Int(dataBytes):
return binascii.b2a_hex(dataBytes).decode()
strLittle = '01020304'
bytesBig = Little2Big(strLittle)
strBig = Bytes2Int(bytesBig)
print(strBig, type(strBig))
str → int
import binascii
def Little2Big(strLittle):
return int(strLittle, 16).to_bytes(4, 'little')
def Bytes2Int(dataBytes):
return int((binascii.b2a_hex(dataBytes).decode()), 16)
strLittle = '01020304'
bytesBig = Little2Big(strLittle)
intBig = Bytes2Int(bytesBig)
print(intBig, type(intBig))