这是python代码。在
from BitVector import *
MX = BitVector(bitstring = '00011011')
MSB_check = BitVector(bitstring = '10000000')
def multiplication_logic(num):
num = num.shift_left(1) # left shift
MSB_num = num & MSB_check # AND num with 1000 0000 to get only MSB
if MSB_num.intValue() != 0:
num = num ^ MX #XOR with 00011011
return num
for indexOfOneInPoly2 in range (0,7):
if polynomial_2[indexOfOneInPoly2] == 1 and indexOfOneInPoly2 != 0:
for numberOfIndexTimes in range (0,indexOfOneInPoly2):
temp = multiplication_logic(polynomial_1)
print(temp)
polynomial_3 = polynomial_3 + temp
print(polynomial_3)
对于上面的代码,我得到了错误
^{pr2}$如何使我的函数将参数作为一个位向量(因为我认为这就是造成问题的原因)
看起来
BitVector.shift_left()
方法返回None
,大概是因为位向量在的地方发生了变异。在无需重新分配
num
在这种情况下,只需使用:如果您使用的是^{} package ,则需要升级到3.1或更高版本(当前版本是3.4.4),因为该版本在}方法中添加了{}。在
BitVector.shift_left()
和{从项目变更日志:
相关问题 更多 >
编程相关推荐