Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert to bin problem
#1
hi, sorry for my bad english,
i tried to create phash compare using "VideoHash"

#pip install videohash
from videohash import VideoHash
import time
start_time = time.time()
path = "input.mp4"
a = VideoHash(path=path)
print(a)
print(type(a))
b = str(a)
print(b)
print("len :",len(b))
print(type(b))
c = int(b,2)
print(c)
print(type(c))
d = bin(c)
print(d)
print("len :",len(d))
print(time.time() - start_time,"Seconds")
and the result:
Output:
0b0000100100001110111000100111111101100001011000010100000000000000 <class 'videohash.videohash.VideoHash'> 0b0000100100001110111000100111111101100001011000010100000000000000 len : 66 <class 'str'> 652708032737787904 <class 'int'> 0b100100001110111000100111111101100001011000010100000000000000 len : 62 9.695210933685303 Seconds
but the number of digits after conversion is different, the original is 66, and the converted is 62,
i tried to using format( '#064b') but it for string data,
i need it because the binary needs to compare using a bitwise technique
def hamming_distance(a, b):
  return bin(a ^ b).count('1')
print(hamming_distance(a, b))
please help me
Reply
#2
Conversion to int removed the zeros at the beginning. You could simply add a 1 at the beginning
s = '1'+ a[2:]
c = int(s)
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
(Apr-19-2024, 05:21 AM)Gribouillis Wrote: Conversion to int removed the zeros at the beginning. You could simply add a 1 at the beginning
s = '1'+ a[2:]
c = int(s)
thank you for the reply,
the main problem, the standard is 64-bit data,
it can be stated at 0b00, to 0b11
and the target is bin(ary) for bitwise operation
Reply
#4
ok, i solve it by split it by chars
for i in range(2,len(str(a))):
    print(str(a)[i])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert From PDf into JPEG Problem koklimabc 4 1,086 Sep-05-2023, 06:44 AM
Last Post: Gribouillis
  Convert string to float problem vasik006 8 3,445 Jun-03-2022, 06:41 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020