# Is it possible to define all bitwise operators using a 'bitwise nand' similar to how all boolean logic can be built using just 'boolean nand'?

`Nand` is known as a 'universal' logic gate, because it allows you define all other boolean logic gates:

``````not(x) = nand(x,x)
and(x, y) = not(nand(x, y))
or(x, y) = nand(not(x), not(y))
nor(x, y) = not(or(x, y))
xor(x, y) = nand(nand(a, nand(a, b)), nand(b, nand(a, b)))
``````

This is known as nand-logic, and is commonly used in modern computers because a transistor can be made to behave just like a nand-gate.

I am wondering if it is possible to do something similar with the bitwise operations. Can an e.g. bitwise nand (bnand) be used to define `bnot`, `bor`, `band`, `bnor`, `bxor`? Is there an universal bitwise operation?

For example the x86 instruction set has: AND, OR, XOR, NOT. These all are performed in one single cycle as far as I know, so that there would be no benefit by replacing them with several NAND operations. It also has ANDN which is an equivalent for `((NOT x) AND y)` that could be generated by a clever optimization compiler to gain a cycle.