Hi Alan,
The code works fine except for the one command.
Got the expected result with the shiftleft.
The space in the error, was this text box trying to be "helpful" and added the space.
Traceback (most recent call last):
File "<pyshell#97>", line 1, in <module>
bm1 == bm3.shiftright(3)
AttributeError: 'int' object has no attribute 'shiftright'
Code:
class BitMask(int):
def AND(self,bm):
return BitMask(self & bm)
def OR(self,bm):
return BitMask(self | bm)
def XOR(self,bm):
return BitMask(self ^ bm)
def NOT(self):
return BitMask(~self)
def shiftleft(self, num):
return BitMask(self << num)
def shiftright(self, num):
return BitMask(self >> num)
def bit(self, num):
mask = 1 << num
return bool(self & mask)
def setbit(self, num):
mask = 1 << num
return BitMask(self | mask)
def zerobit(self, num):
mask = ~(1 << num)
return BitMask(self & mask)
def listbits(self, start=0,end=None):
if end: end = end if end < 0 else end+2
return [int(c) for c in bin(self)[start+2:end]]
I've tried it with both the code in the book and the supplied same error.
I'm using IDLE Python Shell 3.5.2 Tk version 8.5.9
and
Eclipse Platform
Version: Neon (4.6)
Build id: I20160606-1100
On Mac OS-X 10.9.5
If that helps.
Regards,
G*