我被困在一个问题上,尽管我找不到比较是如何出错的。我正在尝试做多项式长除法模2。
while len(binCrcGen) <= len(binPayload) and binPayload:
if binPayload[0] == binCrcGen[0]:
del binPayload[0]
for j in range(len(binCrcGen)-1):
if binPayload[j] == binCrcGen[j+1]:
binPayload.insert(binPayload[j],0)
del binPayload[j+1]
print(binPayload, "binPayload")
else:
binPayload.insert(binPayload[j],1)
del binPayload[j+1]
print(binPayload, "binPayload")
但是我的输出给了我:
Input the binary data payload: 10010
Input the binary representation of the CRC generator: 11
[1, 0, 1, 0] binPayload
[1, 1, 0] binPayload
[1, 0] binPayload
[1] binPayload -- wrong here 1 xor 1 should bring 0 to list.
[1] Remainder
[1, 1] binCrCGen
The data transmitted with the payload 1001 is protected by the CRC 11 is 10011
当手动计算它时,我得到一个 00 的余数,它变成一个空白列表,因为空白列表被删除了。