convert to bin problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: convert to bin problem (/thread-41987.html) |
convert to bin problem - kucingkembar - Apr-19-2024 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: 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 RE: convert to bin problem - Gribouillis - Apr-19-2024 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) RE: convert to bin problem - kucingkembar - Apr-19-2024 (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 beginningthank 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 RE: convert to bin problem - kucingkembar - Apr-19-2024 ok, i solve it by split it by chars for i in range(2,len(str(a))): print(str(a)[i]) |