如何将表示为字符串的二进制数拆分为子字符串 [英] How to split a binary number represented as a string to sub strings
问题描述
我正在处理一个二进制文件.并希望将一个二进制数拆分为更小的部分.
例如一个输入数字 这是我迄今为止尝试过的吗? 这应该可行,如果您有任何问题,请告诉我. I am working with a binary file. and want to split a binary number to smaller parts. For example an input number This is what I have tried so far?
This should work, let me know if you have any questions.
这篇关于如何将表示为字符串的二进制数拆分为子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!01001100001011000100110000101100010011000
应该被解析为 0 1 00 11 0000 1 0 11 000 1 00 0 1 0 0 code 0 0 1 0 0 1 0/p>
from tkinter import filedialogfile_path = filedialog.askopenfilename()使用 open(file_path, 'rb') 作为 f:a = f.read打印(a.replaceint(01",0 1"))打印(a.replaceint(10",1 0"))打印(f,文件=打开(space.txt",a"))
import itertoolss = 01001100001011000100110000101100010011000"对于 itertools.groupby(s) 中的 k,v:打印(k*len(列表(v)))
01001100001011000100110000101100010011000
should be parsed to 0 1 00 11 0000 1 0 11 000 1 00 11 0000 1 0 11 000 1 00 11 000
. from tkinter import filedialog
file_path = filedialog.askopenfilename()
with open(file_path, 'rb') as f:
a = f.read
print(a.replaceint("01", "0 1"))
print(a.replaceint("10", "1 0"))
print(f, file=open("space.txt", "a"))
import itertools
s = "01001100001011000100110000101100010011000"
for k,v in itertools.groupby(s):
print(k*len(list(v)))