这是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)
对于上面的代码,我得到了错误
Traceback (most recent call last):
File "<pyshell#126>", line 4, in <module>
temp = multiplication_logic(polynomial_1)
File "<pyshell#124>", line 3, in multiplication_logic
MSB_num = num & MSB_check
TypeError: unsupported operand type(s) for &: 'NoneType' and 'BitVector'
如何使我的函数将参数作为 BitVector (因为这是我认为造成问题的原因