【发布时间】:2019-06-23 09:59:53
【问题描述】:
我正在尝试使用 bytearray 对哈希算法进行一些计算,但不断收到有关 ^ 操作数类型的错误。我已经制作了一些其他似乎效果很好的方法,但是使用这种方法时,它会不断出错。下面是代码:
def showstate(a):
i = 0
buf = bytearray()
width = 17
print (type(a))
while i < 8 * width:
buf.append(buf ^ (1 and a[i])<<(7-(i%8)))
#buf ^= (1 and a[i])<<(7-(i%8))
#print ("absc")
if (((i%8) == 7) and (i)):
print("%02x"%buf, end = '')
buf = 0
i += 1
我已经尝试查看a 拥有的数据类型——它显示bytearray 我认为buf 的计算没有任何问题。为什么总是报错:
TypeError: unsupported operand type(s) for ^: 'bytearray' and 'int'
【问题讨论】:
标签: python arrays python-3.x operators byte