To fix this issue Integers are nothing but sequence of bits in the computer. So, if you get integer, let's say: 333 it is a sequence of bits 101001101 to the computer. It doesn't need any unpacking into bits. It is bits. code :
def detect(bitmask,check=(18,22,23,24)):
checkmask=sum(2**x for x in check)
if (bitmask & checkmask) > 0:
print "There are some problems"
else:
print "Everything OK"
Share :

last 5 bits of a bitmask
By : Saiful Saif
Date : March 29 2020, 07:55 AM
Hope this helps I have a bitmask (stored as a short). For various purposes, I want to zero out all but the last 5 bits  I'm sure there is an easy to way to do this via bitwise operators, but it eludes me. , Use something like: code :
x & 0x1f
1010 1101 1011 0111
& 0000 0000 0001 1111

0000 0000 0001 0111

Bitmask for obtaining the value in between X and Y bits
By : laurent
Date : March 29 2020, 07:55 AM
like below fixes the issue A general approach would be to select the byte inside the square brackets, then mask off the bits you care about using the single &, and then right shift the byte by the number of bits it is from the lsb, then you have the integer value. e.g.

Bitmask and selecting even bits
By : Ben2014
Date : March 29 2020, 07:55 AM
around this issue The left to right thing is where you make a mistake. See what happens when you actually do it: code :
your number: 1111 1111 1111 1111 1111 1111 1111 1111
Mask: 1010 1010 1010 1010 1010 1010 1010 1010
result: 1010 1010 1010 1010 1010 1010 1010 1010

Fastest Way to XOR all bits from value based on bitmask?
By : Natalia Stavisky
Date : March 29 2020, 07:55 AM
wish of those help If I understood this question correctly, what you want is to get every bit from VALUE that is set in the MASK, and compute the XOR of those bits. First of all, note that XOR'ing a value with 0 will not change the result. So, to ignore some bits, we can treat them as zeros. code :
int set_bits = __builtin_popcount(value & mask);
return set_bits % 2;

Bitmask to flip bits ... without XOR?
By : Waheed Gondal
Date : March 29 2020, 07:55 AM
seems to work fine You can't build a NOT gate out of AND and OR gates. As I was asked to explain, here it is nicely formatted. Let's say you have any number of AND and OR gates. Your inputs are A, 0 and 1. You have six possibilities as you can make three pairs out of three signals (pick one that's left out) and two gates. Now:

