# binary

## How to convert string to binary for setpassword() function in Python

How to convert string to binary for setpassword() function in Python Question: This code writes to a string-type password random numbers and symbols. Then create a zip file and write there another zip file and then It needs to set a password to the zip file, but It wants a bin type, not a string …

## Python bytes to binary string – how 4 bytes can be 29 bits?

Python bytes to binary string – how 4 bytes can be 29 bits? Question: I need to read time data from sensor. Here are the instructions from manual: I have written code in Python, but I feel like there should be some better way: # 1 data_bytes = b’x43x32x21x10′ print(‘data_bytes: ‘, data_bytes, len(data_bytes)) # why …

## Multi-Thread Binary Tree Search Algorithm

Multi-Thread Binary Tree Search Algorithm Question: I find implementing a multi-threaded binary tree search algorithm in Python can be challenging because it requires proper synchronization and management of multiple threads accessing shared data structures. One approach, I think is to achieve this would be to use a thread-safe queue data structure to distribute search tasks …

## Quickly assigning an id to a given combination of bits

Quickly assigning an id to a given combination of bits Question: the context behind my issue is not important, as my question itself is fairly self-contained. Im currently trying to assign numbers to sequences of bits. Such that, if i ask functionA for bit sequence 42, it would return the corresponding bits, say "0110101011…" (not …

## XOR'ing each bit of a binary string in Python

XOR'ing each bit of a binary string in Python Question: I have two binary strings (not integer) for example 0101 and 0010, I need to XOR these two binary strings and then XOR the each bit of the result again. XOR of these two results in 0111, now I want to achieve the result 0 …

## Generating a byte with an array of bit positions?

Generating a byte with an array of bit positions? Question: Let’s say I have a list of numbers: [1, 2, 5] I need to generate a byte that represents the 5, 2 and 1 "position on". Which will result in the byte of value 19. 00010011 Is there an easy way to do this that …

## find a path to a given node in binary tree – Python

find a path to a given node in binary tree – Python Question: I’m stuck finding the path of the given node so I can find the right side but not the left side. class Node: def __init__(self, key): self.left = None self.right = None self.val = key def path(self, k): if not self.val: return …

## How to replace the independent 1 with 0 in binary number using only bitwise operations?

How to replace the independent 1 with 0 in binary number using only bitwise operations? Question: By "independent 1" I mean 1 that has no other 1 next to it ("010" or "10" and "01" at the ends of the num.) If the 1 doesn´t have any 1 next to it, it will change to …