我有一个包含一系列比特的文本文件,在ASCII:蟒字面二进制进制转换
cat myFile.txt
0101111011100011001...
我想写这对以二进制模式的其它文件,这样我可以读取它一位君主。我怎么能达到?我试过已经用代码转换它:
f2=open(fileOut, 'wb')
with open(fileIn) as f:
while True:
c = f.read(1)
byte = byte+str(c)
if not c:
print "End of file"
break
if count % 8 is 0:
count = 0
print hex(int(byte,2))
try:
f2.write('\\x'+hex(int(byte,2))[2:]).zfill(2)
except:
pass
byte = ''
count += 1
但这并没有达到我计划要做的。你有什么提示吗?
谢谢你很多_ :-) – user1225343