logic
symbol | name | formula |
---|---|---|
¬ | negation | not(a) = 1 - a |
∧ | conjunction | and(a, b) = a * b |
⊼ | alternative denial | nand(a, b) = not(and(a, b)) nand(a, b) = 1 - a * b |
∨ | disjunction | or(a, b) = a + b - a * b |
⊽ | joint denial | nor(a, b) = not(or(a, b)) nor(a, b) = 1 - (a + b - a * b) |
⊻ | exclusive or | xor(a, b) = a + b - 2 * a * b |
biconditional | xnor(a, b) = not(xor(a, b)) xnor(a, b) = 1 - (a + b - 2 * a * b) |
a | ¬a |
---|---|
0 | 1 |
1 | 0 |
a | b | a ∧ b | a ⊼ b | a ∨ b | a ⊽ b | a ⊻ b | a XNOR b |
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 |
bitwise
<< # shift left
>> # shift right
((x & 1) == 0) # check if x is even
(x & (1 << n)) # check if n-th bit is set
x | (1 << n) # set n-th bit
x & ~(1 << n) # unset n-th bit
x ^ (1 << n) # toggle n-th bit
x & (x - 1) # turn off rightmost 1-bit
x & (-x) # isolate rightmost 1-bit
x | (x - 1) # right propagate rightmost 1-bit
~x & (x + 1) # isolate rightmost 0-bit
x | (x + 1) # turn on rightmost 0-bit