NAND Calculator

Compute a bitwise NAND, the inverse of AND, and see every column of the word laid out.

Operand A
Operand B
NAND result
Runs locally in your browser

About the NAND Calculator

NAND is AND followed by an inversion. Line the two operands up column by column, write a 1 wherever AND would have written a 0, and you have the answer. Because the whole word is inverted at the end, the width of that word decides the result: 0xF0 NAND 0x3C is 0xCF in eight bits but 0xFFCF in sixteen, so the calculator prints the width it used and lets you pin a different one.

Operands may be typed as plain decimal or carry a 0x, 0b or 0o prefix. Auto detect reads the prefix on each line; pinning a base forces every value to be read the same way, which saves prefixing a pasted column. Extra lines in either pane become extra operands and are folded from left to right, so three values give (A NAND B) NAND C. NAND is not associative, so that bracket order is stated on the page rather than left implied.

The output shows the result in decimal, binary, hexadecimal and octal, the signed reading of the same bits for the chosen width, and a stacked bit layout with each operand above the answer. The truth table underneath is the reason NAND matters: it is functionally complete, which means every other logic gate can be built from NAND alone, and that is why real chips are full of them. For the plain conjunction use the AND Calculator, and for the inverted disjunction see the NOR Calculator.

How to use

  1. Type the first value into the Operand A pane, with a prefix such as 0b1010 if it is not decimal.
  2. Put the second value in the Operand B pane.
  3. Pin a Bit width when you are matching a register, because inversion depends on the word size.
  4. Read the bit layout to see which single column produced a 0.

Common questions

Why is 0xF0 NAND 0x3C equal to 0xCF?
The AND of those two values is 0x30, and inverting 0x30 inside an eight bit word gives 0xCF. Widen the word and the leading ones extend with it.
Does the bit width change the answer?
Yes, and only for the inverted gates. The inversion fills every unused high bit with a 1, so an 8-bit result and a 32-bit result differ above bit seven.
How are three or more operands handled?
They are folded from left to right, giving (A NAND B) NAND C. NAND is not associative, so a different grouping would give a different answer.
Why is NAND called a universal gate?
Because NOT, AND, OR and XOR can all be built from NAND gates alone, so a fabrication process only needs to get one gate right.