Yes, there is a way and I suppose it will be blazing fast as this is quite simple operation. function implication($p, $q) { return !$p | $q; } You might want to exchange | to || for your own purposes. Let's generate truth table for this: $values = array(0,1); echo...

python,if-statement,logic,truthtable

Consider doing something along the lines of this: x = 0; if abs(stableAcceleration[0]) > abs(stableAcceleration[1]) : x += 2 if stableAcceleration[0] > 0: x +=1 list = ["normal", "invert", "left", "right"] print(list[x]) That being said, your series of if statements don't cover every case....

You can generate the truth table using a powerset, def power_set(items): n = len(items) for i in xrange(2**n): combo = [] for j in xrange(n): if (i >> j) % 2 == 1: combo.append(1) else: combo.append(0) yield combo # if you want tuples, change to yield tuple(combo) In [13]: list(power_set(l))...

You have it backwards. It is the binary number 1 shifted left by 'x' spots. And that should make sense. If you want to check the 4th spot in the table, represented by 'f', you have to check that f & 10000!=0. You're right, shifting by one is very arbitrary...

Ok now that you rewrote your question to be much clearer. First, getRow needs to take an extra argument: the number of bits. Row 1 with 2 bits produces a different result than row 1 with 64 bits, so we need a way to differentiate that. Second, typically with C++,...