Format Code Now
/

NAND Calculator

CU-24

Enter two numbers such as 12 and 10 and get their bitwise NAND in decimal, signed decimal, hex and binary. NAND is AND followed by NOT, at the bit width you choose.

Runs in your browser. Nothing is uploaded.

Number pairs, one per line (12 10 or 12 NAND 10)

NAND results

How to use it

  1. Type or paste one pair of numbers per line, for example 12 10 or 12 NAND 10.
  2. Pick the bit width (8, 16, 32 or 64) and how numbers without a prefix are read.
  3. Press Calculate NAND for decimal, signed, hex and binary results, Binary view to line the bits up, or Truth table for the one-bit gate.
  4. Copy the result or download it as a text file.

What NAND does

NAND is AND followed by NOT, applied to each bit. A result bit is 0 only when both input bits are 1, and 1 in every other case. The truth table is 0,0 gives 1; 0,1 gives 1; 1,0 gives 1; 1,1 gives 0. Because NOT flips every bit up to the full width, the result depends on the width you pick: 12 NAND 10 is 247 at 8 bits and 4294967287 at 32 bits.

Numbers, widths and signs

Numbers can be decimal, or written with 0x for hex, 0b for binary and 0o for octal. You can also set numbers without a prefix to be binary or hexadecimal. A negative decimal is stored as the matching unsigned value of the chosen width, so -1 at 8 bits is 255. A number that does not fit the width is an error, not a silent cut. Values up to 64 bits are exact.

Limits

Each line takes exactly two operands. NAND is not associative, meaning (a NAND b) NAND c is not the same as a NAND (b NAND c), so chains of three or more are not supported. This is the bitwise operator on whole numbers, not a logic-gate simulator with wires. The Binary view shows both inputs and the result in aligned bits.

Error messages and what to do

MessageWhat it meansFix
Line 1: write two numbers such as 12 10 or 12 NAND 10 (got "abc").The line does not hold exactly two numbers, optionally with the operator word between them.Write two numbers, for example 12 10 or 12 NAND 10.
Line 1: 300 does not fit in 8 bits (allowed -128 to 255).A number is too big for the chosen bit width. The tool refuses it instead of cutting bits off.Choose a wider bit width or use a smaller number.

Questions people ask

What is NAND?

NAND is the opposite of AND. It outputs 0 only when both inputs are 1, and 1 otherwise. In hardware it is a universal gate, meaning any other logic function can be built from NAND gates alone.

How do I calculate NAND of two numbers?

AND the numbers bit by bit, then flip every bit up to your chosen width. For 12 and 10 at 8 bits: 12 AND 10 is 8 (00001000), and flipping gives 11110111, which is 247. The tool shows each step in its Binary view.

Why does the width change the answer?

NOT flips every bit up to the width. At 8 bits the result of 12 NAND 10 has eight bits, 247. At 32 bits it has 32 bits, 4294967287, because the extra high bits become 1.

What is the signed decimal value?

It reads the same bits as a two's complement number, where the top bit is a sign. So 247 at 8 bits is -9. The tool shows both unsigned and signed values.

Can I enter hex or binary numbers?

Yes. Use 0xFF for hex, 0b1100 for binary or 0o17 for octal, or switch the option so numbers without a prefix are read as binary or hexadecimal.

What is the NAND truth table?

Inputs 0,0 give 1; 0,1 give 1; 1,0 give 1; and 1,1 give 0, so the output is 0 only when both inputs are 1. Press Truth table to see it printed in a small grid.

About this tool

NAND is AND followed by NOT, applied bit by bit: a result bit is 0 only when both input bits are 1. Each line holds two whole numbers, with or without the word NAND between them. Numbers can be decimal, 0x hex, 0b binary or 0o octal, or you can choose binary or hexadecimal for numbers without a prefix. The width matters because NOT flips every bit up to that width: 12 NAND 10 is 247 in 8 bits and 4294967287 in 32 bits. A negative decimal is stored as the matching unsigned value of that width, and a number that does not fit the width is an error. 64-bit values are exact (BigInt). Only two operands per line; NAND is not associative, so chains are not supported.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.