【发布时间】:2016-05-05 23:04:01
【问题描述】:
我正在尝试解码位于 .txt 文件中的二进制文件,但我被卡住了。我看不出有任何可能性。
def code(): testestest
ascii = {'01000001':'A', ...}
binary = {'A':'01000001', ...}
print (ascii, binary)
def encode():
pass
def decode(code,n):
f = open(code, mode='rb') # Open a file with filename <code>
while True:
chunk = f.read(n) # Read n characters at time from an open file
if chunk == '': # This is one way to check for the End Of File in Python
break
if chunk != '\n':
# Process it????
pass
如何获取 .txt 文件中的二进制文件并将其输出为 ASCII?
【问题讨论】:
-
哦,是的 :-) 对不起。有没有什么简单的方法可以将 .txt 文件中的二进制文件输出为 ASCII 码?
-
您的意见是什么?预期的输出是多少?这听起来比你想象的要容易。
-
您的答案是here。只需根据您的需要进行修改即可。
-
你不能用
int("01000001', 2)转换成整数然后chr(65)得到char吗?