Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def detect(bitmask, check=(18,22,23,24), bits=32):
- boolmask = np.zeros(len(bitmask), dtype=bool)
- for i, val in enumerate(bitmask):
- bithost = np.zeros(bits, dtype='i1')
- masklist = list(bin(val)[2:])
- bithost[bits-len(masklist):] = masklist
- if len(np.intersect1d(np.nonzero(bithost)[0] ,check)) != 0:
- boolmask[i] = True
- else:
- boolmask[i] = False
- if any(boolmask):
- print("There are some problems")
- else:
- print("It is clean")
- def turn_bits_on(bits):
- n = 0
- for k in bits:
- n = (n | (1 << (k - 1))) if k > 0 else n
- return n
- bits_to_check = turn_bits_on([18, 22, 23, 24])
- def is_ok(value, mask):
- return not (value & mask)
- print(is_ok(24453656, bits_to_check))
- 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"
Add Comment
Please, Sign In to add comment