bitwise-operators

I cant verify seed generation if someone can see what is wrong

I cant verify seed generation if someone can see what is wrong Question: So i got this function that generates seeds makeseed() and now im trying to make a "verify" seed keep in mind that any seed generated IS Correct so i want it so that the user can input seeds and it’ll check if …

Total answers: 1

Fast Bitwise Sum in Python

Fast Bitwise Sum in Python Question: Is there an efficient way to calculate sum of bits in each column over array in Python? Example (Python 3.7 and Numpy 1.20.1): Create numpy array with values 0 or 1 import numpy as np array = np.array( [ [1, 0, 1], [1, 1, 1], [0, 0, 1], ] …

Total answers: 3

What are the value states of read/write in selectors.EVENT_READ | selectors.EVENT_WRITE?

What are the value states of read/write in selectors.EVENT_READ | selectors.EVENT_WRITE? Question: In the question Python – non-blocking sockets using selectors the following code is used: events = selectors.EVENT_READ | selectors.EVENT_WRITE The values of event_read or event_write flags are not mentioned nor explained at https://docs.python.org/3/library/selectors.html. Neither is an explanation give in the select() module or …

Total answers: 1

Getting the position of 1-bits in a python Long object

Getting the position of 1-bits in a python Long object Question: Let’s say I have a very very large python integer, in python 2.7 (though if I need to, I don’t mind switching to python 3). Something bigger than say, 2^100000. What is the fastest way by which I can find the positions of all …

Total answers: 3

Infinite loop while adding two integers using bitwise operations?

Infinite loop while adding two integers using bitwise operations? Question: I am trying to solve a problem, using python code, which requires me to add two integers without the use of ‘+’ or ‘-‘ operators. I have the following code which works perfectly for two positive numbers: def getSum(self, a, b): while (a & b): …

Total answers: 3

Logical vs. bitwise operator AND

Logical vs. bitwise operator AND Question: I don’t understand the difference between & and and, even if I read some other questions about it. My code is: f=1 x=1 f==1 & x==1 Out[60]: True f==1 and x==1 Out[61]: True f=1 x=2 f==1 and x==2 Out[64]: True f==1 & x==2 Out[65]: False Why is it the …

Total answers: 4

Convert to binary and keep leading zeros

Convert to binary and keep leading zeros Question: I’m trying to convert an integer to binary using the bin() function in Python. However, it always removes the leading zeros, which I actually need, such that the result is always 8-bit: Example: bin(1) -> 0b1 # What I would like: bin(1) -> 0b00000001 Is there a …

Total answers: 11