小端序str → 大端序str

一般是为了打印日志自己看着方便

  1. def Little2Big(strLittle):
  2. lenStr = len(strLittle)
  3. time = int(lenStr/2)
  4. j = 0
  5. strBig = ''
  6. for i in range(time):
  7. str = strLittle[lenStr-2-j : lenStr-j]
  8. j += 2
  9. strBig += str
  10. return strBig
  1. def Little2Big(strLittle):
  2. strBig = (int(strLittle, 16).to_bytes(4, 'little')).hex()[:6].upper()
  3. return strBig
  1. import binascii
  2. def Little2Big(strLittle):
  3. return int(strLittle, 16).to_bytes(4, 'little')
  4. def Bytes2Int(dataBytes):
  5. return binascii.b2a_hex(dataBytes).decode()
  6. strLittle = '01020304'
  7. bytesBig = Little2Big(strLittle)
  8. strBig = Bytes2Int(bytesBig)
  9. print(strBig, type(strBig))

str → int

  1. import binascii
  2. def Little2Big(strLittle):
  3. return int(strLittle, 16).to_bytes(4, 'little')
  4. def Bytes2Int(dataBytes):
  5. return int((binascii.b2a_hex(dataBytes).decode()), 16)
  6. strLittle = '01020304'
  7. bytesBig = Little2Big(strLittle)
  8. intBig = Bytes2Int(bytesBig)
  9. print(intBig, type(intBig))