class Bit: def __init__(self, v): self.value = 0 if v != 0: self.value = 1 def set(self, v): if v == 0: self.value = 0 else: self.value = 1 def get(self): return self.value def bit_and(self, otherBit): if self.value == 1 and otherBit.get() == 1: return 1 else: return 0 def print_and_table(): print "A".rjust(5) + "B".rjust(5) + " A and B" b1 = Bit(0) b2 = Bit(0) for i in range(2): for j in range(2): b1.set(i) b2.set(j) print str(i).rjust(5) + str(j).rjust(5) + \ str(b1.bit_and(b2)).rjust(5) def print_and_table_so_so(): print "A " + "B " + " A and B" b1 = Bit(0) b2 = Bit(0) for i in range(2): for j in range(2): b1.set(i) b2.set(j) print str(i) + " " + str(j) + " " + str(b1.bit_and(b2)) #printAndTable()