我从一个文件中转储了一长串的位。现在,我想取这个位序列,并能从中提取每8位。例如:
100010010101000001001110010001110000110100001010
000110100000101000000000000000000000000000001101
010010010100100001000100010100100000000000000000
etc
会给出:
^{pr2}$到目前为止,我有以下代码:
#/usr/bin/python
with open("thebits.txt", 'r') as f:
content = [x.strip('\n') for x in f.readlines()]
{//logic to extract every 8th bit from each line and print it}
如何从每行中提取每8位? . 在
可以使用简单切片:
示例文件给出了:
^{pr2}$片
[7::8]
提供从第8个开始的每8个字符(从0索引的7个)。在假设您希望每一行分开:
相关问题 更多 >
编程相关推荐