For two bits, there are 4 possible combinations of them: a | b 0 | 0 0 | 1 1 | 0 1 | 1 That means that there 16 possible truth tables. For each of them we should be able to implement a bit-wise version of it that would work on all of the bit positions.
-
-
Show this thread
-
The first is easy, it's just always 0. So: a|b|c 0|0|0 0|1|0 1|0|0 1|1|0 code: = 0
Show this thread -
Next is the familiar AND operation. a&b a|b|c 0|0|0 0|1|0 1|0|0 1|1|1 code: a & b
Show this thread -
Next is the first one where things get a little weird. I've never had to use this one. a|b|c 0|0|0 0|1|0 1|0|1 1|1|0 code: a & (~b)
Show this thread -
Now another easy one: a|b|c 0|0|0 0|1|0 1|0|1 1|1|1 code: = a
Show this thread -
O.k another weird one I've never used: a|b|c 0|0|0 0|1|1 1|0|0 1|1|0 code: (~a) & b
Show this thread -
another simple one: a|b|c 0|0|0 0|1|1 1|0|0 1|1|1 code: = b
Show this thread -
time for XOR, the one I screwed up: a|b|c 0|0|0 0|1|1 1|0|1 1|1|0 code: a ^ b
Show this thread -
next comes OR: a|b|c 0|0|0 0|1|1 1|0|1 1|1|1 code: a | b
Show this thread -
NOR, common in electronics, rare in code: a|b|c 0|0|1 0|1|0 1|0|0 1|1|0 code: ~( a | b )
Show this thread -
Bitwise equality: a|b|c 0|0|1 0|1|0 1|0|0 1|1|1 code: ~(a^b)
Show this thread -
Deceptively simple: a|b|c 0|0|1 0|1|0 1|0|1 1|1|0 code: ~b
Show this thread -
This one is hard to even think of a use for: a|b|c 0|0|1 0|1|0 1|0|1 1|1|1 code: (~b) | (a & b)
Show this thread -
An inversion of an earlier simple one: a|b|c 0|0|1 0|1|1 1|0|0 1|1|0 code: ~a
Show this thread -
Another inversion, also probably useless: a|b|c 0|0|1 0|1|1 1|0|0 1|1|1 code: (~a) | (a & b)
Show this thread -
Last one! set all of the bits: a|b|c 0|0|1 0|1|1 1|0|1 1|1|1 code: = ~0
Show this thread -
That's all 16! If you think I need to number them, this thread wasn't for you ;-) just read the right most column as the number MSB to LSB top to bottom. Any good names for any of the un-named ones?
Show this thread
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.