November 6th, 2012, 05:39 PM
Join Date: Dec 2009
Time spent in forums: 2 h 24 m 28 sec
Reputation Power: 0
Problem working with bitmasks
I have some binary data and I want to see if a certain bit is set and then take action.
I have something like this:
for i in xrange(0, length):
corr = fh.read(1)
mac = fh.read(6)[-3:]
print hexlify(corr) + " - " + hexlify(mac)
print "DELETE NODE " + hexlify(mac)
print "NEW INFO " + hexlify(mac)
print "NEW MAC "+ hexlify(mac)
print "NEW FW " + hexlify(mac)
And I really don't like how I first convert the number into a string with hexlify and then convert it back into an int base 16 just to apply the bitmask and it doesn't seem to work when corr = 0x10 anyways. How can I improve this and make it work?
Oh and fh
is a StringIO object.