binary

Python: How to convert string of an encoded Unicode variable to a binary variable

Python: How to convert string of an encoded Unicode variable to a binary variable Question: I am building an app to transliterate Myanmar (Burmese) text to International Phonetic Alphabet. I have found that it’s easier to manipulate combining Unicode characters in my dictionaries as binary variables like this b’xe1x80xadxe1x80xafxe1x80x84′: ‘áɪŋ̃’, #’ိုင’ because otherwise they glue …

Total answers: 1

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 …

Total answers: 1

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 …

Total answers: 4

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 …

Total answers: 2

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 …

Total answers: 3

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 …

Total answers: 1

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 …

Total answers: 1

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 …

Total answers: 1

Dividing a 24-digit binary number to 3 equal parts

Dividing a 24-digit binary number to 3 equal parts Question: I’d like to know how can I divide a 24-digit binary number which is taken from user in python to 3 parts and then put different conditions on each of these 3 parts. e.g: input => 111100011110110100100100 divide the input to 3 equal parts (each …

Total answers: 1