我正在阅读Python中的二进制文件,文件格式的文档说:
Flag (in binary)Meaning
1 nnn nnnn Indicates that there is one data byte to follow
that is to be duplicated nnn nnnn (127 maximum)
times.
0 nnn nnnn Indicates that there are nnn nnnn bytes of image
data to follow (127 bytes maximum) and that
there are no duplications.
n 000 0000 End of line field. Indicates the end of a line
record. The value of n may be either zero or one.
Note that the end of line field is required and
that it is reflected in the length of line record
field mentioned above.
在阅读文件时,我期待我返回1 nnn nnnn的字节,nnn nnnn部分应该是50。
我已经能够做到这一点使用以下内容:
flag = byte >> 7
numbytes = int(bin(byte)[3:], 2)但是,numbytes计算感觉像是一个便宜的解决方法。
我可以做更多的数学计算来完成numbytes的计算吗?
你会如何处理这个问题?