I would like to apply a bit mask to a variable in python to figure out which bits are set. I’ve been trying around but haven’t figured out the correct way to do it. My variable is binary and to display its value, i use th function hexlify():
corr = fh.read(1)
mac = fh.read(6)[-3:]
print "corr "+ hexlify(corr)
no I have troubles to apply the bitmask to corr:
print hexlify(corr&0x01)
it says
TypeError: unsupported operand type(s) for &: 'str' and 'int'
but why is that? Any help would be appreciated!
Thank you very much!
Now, I don’t like this but it seems to work:
this converts corr to a hex string which again gets converted baclk to an integer, base 16 before the mask gets applied….. any hints on how I could solve this otherwise would be appreciated.
Thanks!