Beetwise

Bitwise NAND

NAND is an AND with the result inverted.

A bit of the result has the value 0 only when both inputs have the value 1 at that position.

No language has a NAND operator, so the code writes ~(a & b).

Try bitwise NAND in the bit editor

The result of 12 NAND 10 in an 8-bit register. Edit the expression or select a bit to flip it.

7
6
5
4
3
2
1
0
-9
value · 8 bits · signed
hex
0xF7
Read the bits as

The truth table of NAND

The truth table of NAND
ABA NAND B
001
011
101
110

Where bitwise NAND is used

A NAND gate builds a whole chip, because every other gate follows from it.

A flash memory cell array carries the name NAND for the same reason.

A mask that clears the common bits of two values is a NAND.

Bitwise NAND: points to note

  • The result depends on the bit width. In 8 bits, 12 NAND 10 gives 247, and in 16 bits it gives 65527.
  • The NOT part sets every bit above the operands, so the result looks large.
  • Beetwise marks the entry as signed, because the raw result of NOT is negative.
  • NAND is not the same as NOT AND applied to one operand. The order of the two steps matters.

The full bit editor

The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.

Open this value in the full editor

Questions about bitwise NAND

What is 12 NAND 10?
In 8 bits the result is 247. The AND gives 8, and the NOT of 8 gives 247 in 8 bits.
How do I write NAND in C?
Write ~(a & b). Cast or mask the result to the width you need.
Why is a NAND gate special?
Every other gate follows from NAND alone, so one gate type builds a whole logic family.