36 lines
899 B
Python
36 lines
899 B
Python
|
|
|
|
|
|
|
|
class save:
|
|
def __init__(self) -> None:
|
|
pass
|
|
def save(self,data:bytearray):
|
|
d=data[1:]
|
|
for i in range(20):
|
|
self.save_item(d[i*28:i*28+28])
|
|
def save_item(self,d:bytearray):
|
|
s='=\"'+d[0:8].hex()+'\"'+','
|
|
s+='=\"'+self.hex2bit(d[8:10])+'\"'+','
|
|
s+=self.hex2int(d[10:])
|
|
print(d[8:10].hex(' '))
|
|
print(s)
|
|
with open("./file/save.csv","+a") as f:
|
|
f.write(s+'\n')
|
|
def hex2int(self,d:bytearray):
|
|
s=""
|
|
for i in range(len(d)//2):
|
|
s+=str(d[i*2]|(d[i*2+1]<<8))+','
|
|
return s
|
|
def hex2bit(self,d:bytearray):
|
|
s=""
|
|
for i in range(len(d)*8):
|
|
if(d[i//8]&(1<<(i%8))!=0):
|
|
s+='1'
|
|
else:
|
|
s+='0'
|
|
if((i>0) and ((i+1)%8==0) and ((i+1)<len(d)*8)):
|
|
s+='_'
|
|
return s
|
|
|