I was following this library "dhash" , but get error when using its dhash.get_num_bits_different
:
def get_num_bits_different(hash1, hash2):
return bin(hash1 ^ hash2).count('1')
hash1 = '3d77xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
hash2 = '9301xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
get_num_bits_different(hash1, hash2)
>>
TypeError: unsupported operand type(s) for ^: 'str' and 'str'
Convert the string to an int like:
get_num_bits_different(int(hash1, 16), int(hash2, 16))
def get_num_bits_different(hash1, hash2):
return bin(hash1 ^ hash2).count('1')
hash1 = '3d77'
hash2 = '9301'
print(get_num_bits_different(int(hash1, 16), int(hash2, 16)))
10
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.