代码拉取完成,页面将自动刷新
同步操作将从 oldk007/jt808设备管理系统 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import binascii
import os
import time
class Tools:
# 字符串转16进制
def StrToHex(self, tempStr):
s = ''
for each in tempStr:
#s += hex(ord(each))[2:]
if ord(each) <16:
ts='0'+hex(ord(each))[2:]
else:
ts=hex(ord(each))[2:]
s += ts
return s.upper()
# 16进制转8位的2进制
def HexStrTo8Bin1(self, tempHex):
res = ''
for each in bytes.fromhex(tempHex):
sBin = bin(each)[2:]
eightNum = 8 - len(sBin)
if (0 != eightNum):
sBin = eightNum * '0' + sBin
res += sBin
return res
# 整形转16进制,缺位补0
def IntToHex(self, tempInt, digit):
if tempInt >= 0:
sHex = hex(tempInt)[2:]
num = digit - len(sHex)
if (0 != num):
sHex = num * '0' + sHex
else:
sHex = hex(tempInt & 0xFFFF)[2:]
return sHex
# 中文转16进制
def ChrToHex(self, tempChr):
sHex = str(binascii.b2a_hex(tempChr.encode('gbk')))[2:-1].upper()
return sHex
# 16进制转中文
def HexToChr(self, tempHex):
chr = binascii.a2b_hex(tempHex).decode('gbk')
return chr
# bytes转16进制
def ByteToHex(self, bins):
return ''.join(["%02X" % x for x in bins]).strip()
# image转16进制
def ImageToHex(self, filepath):
file = filepath
with open(file, 'rb') as f:
content = f.read()
sBin = binascii.hexlify(content)
sHex = str(sBin)[2:-1]
return sHex
# 返回字节流的十六进制字节流
def BinToHex(self, content):
sBin = binascii.hexlify(content)
sHex = str(sBin)[2:-1]
return sHex
# 获取文件大小,转16进制
def getDocSizeToHex(self, filepath):
size = os.path.getsize(filepath) # 获取文件大小
sHex = hex(size)[2:]
return sHex
# 获取文件名称,转16进制
def getDocNameToHex(self, filepath):
filename = os.path.basename(filepath) # 获取文件路径,文件名称
# file_base = filename.split('.')[0]
# file_type = filename.split('.')[1]
# # print(file_base, file_type)
# localtime = time.strftime("%y%m%d%H%M%S", time.localtime())
# filename_time = file_base + localtime + '.' + file_type
# print(filename_time)
sHex = self.StrToHex(filename)
return sHex
# 16进制转字符串
def HexToStr(self, tempHex):
content = binascii.a2b_hex(tempHex).decode("utf8")
return content
# print(bytes(b'~\x81\x00\x00\t\x01Rpa\x11\x11$c\x00\x01\x00vmsgps\x80~').decode('ascii'))
if __name__ == '__main__':
t = Tools()
#print(t.ImageToHex('../../attachment/52204.jpg'))
#print(t.getDocSizeToHex('../../attachment/52204.jpg'))
#print(t.getDocNameToHex('../../attachment/52204.jpg'))
#print(t.HexToStr("35323230342E6A7067"))
num = -55
#print(t.IntToHex(num, 8))
print(t.ChrToHex('京'))
print(t.HexToChr('bea9415050303033'))
print(t.HexToChr('BEA9'))
print(t.StrToHex('~\x81\x00\x00\t\x01F\x037i \x00\x00\x1b\n\x00123456\xa4~'))
print(t.HexToChr('38383338383334'))
print(t.HexToChr('3732333032'))
print( int('001f',16))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。