##### convert to bin problem
 convert to bin problem kucingkembar Lumberjack Posts: 112 Threads: 37 Joined: Nov 2021 Reputation: Apr-19-2024, 02:50 AM 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 0b0000100100001110111000100111111101100001011000010100000000000000 len : 66 652708032737787904 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 Posts: 4,554 Threads: 70 Joined: Jan 2018 Reputation: Apr-19-2024, 05:21 AM 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 kucingkembar Lumberjack Posts: 112 Threads: 37 Joined: Nov 2021 Reputation: Apr-19-2024, 06:12 AM (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 kucingkembar Lumberjack Posts: 112 Threads: 37 Joined: Nov 2021 Reputation: Apr-19-2024, 12:53 PM 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,168 Sep-05-2023, 06:44 AM Last Post: Gribouillis Convert string to float problem vasik006 8 3,531 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