AND OR NOT Calculator

Compute bitwise AND, OR, NOT, NAND, NOR, and XNOR operations on binary numbers

0 bits
0 bits

Try an example:

Enter binary inputs, select an operation, and click Calculate to see the bitwise step-by-step result.

Tip: Inputs are automatically padded to match lengths. For NOT operations, only Input A is used. Results show both binary and hexadecimal values.

Bitwise Operations Explained

Bitwise operations work directly on the binary representation of numbers, processing each bit independently. If you've worked with low-level programming, embedded systems, or network protocols, these operations are part of your daily toolkit. Even if you're just getting started with binary logic, understanding AND, OR, and NOT is the foundation for everything else in digital computing.

AND — Returns 1 only when both input bits are 1. Think of it as a gate that says "both conditions must be true." In real-world debugging, AND is what you use when you want to mask specific bits and check whether they're set. 1100 AND 1010 = 1000 because only the leftmost bit is set in both inputs.

OR — Returns 1 when at least one input bit is 1. This is the "any condition is true" gate. If you're setting a configuration flag and want to enable multiple features at once, OR is your operation. 1100 OR 1010 = 1110 because every bit that's set in either input stays set.

NOT — Flips every bit. It's the simplest operation: each 0 becomes 1, and each 1 becomes 0. NOT is a unary operation, meaning it only needs one input. NOT 1100 = 0011. In programming, NOT is how you invert a flag or turn off every bit that was previously on.

Truth Tables for All Operations

Here are the complete truth tables for every operation this calculator supports. Each table shows what happens for every possible pair of input bits (A and B), or in the case of NOT, for every possible input bit.

ABANDORNANDNORXNOR
0000111
0101100
1001100
1111001
ANOT A
01
10

Note: NAND = NOT AND (invert AND result), NOR = NOT OR (invert OR result), XNOR = NOT XOR (1 when both bits are equal).

Practical Applications

  • AND for masking bits — Want to check if a specific bit is set? AND your value with a mask that has 1s only at the positions you care about. If the result is non-zero, those bits are set. This is how permission systems work in Unix (chmod masks are bitwise AND operations).
  • OR for setting bits — Need to enable certain flags without touching others? OR your value with a mask of the bits you want to set. Each 1 in the mask forces the corresponding bit to 1. This is how you combine permission flags or enable hardware features in embedded systems.
  • NOT for flipping bits — Need to clear a specific range of bits? NOT the mask first, then AND it with your value. NOT is also used in two's complement arithmetic to compute negative numbers: -x = NOT(x) + 1.
  • NAND as a universal gate — In digital circuit design, NAND is called a universal gate because you can build any other logic gate (AND, OR, NOT, NOR, XOR, XNOR) using only NAND gates. A CPU is, at its core, a massive network of NAND gates.

Bitwise vs. Logical

This is a distinction that trips up a lot of beginners, so it's worth spelling out clearly.

Bitwise operators (&, |, ~ in most programming languages) operate on each bit of their operands independently. Given two 8-bit numbers, a bitwise AND produces another 8-bit number where each bit is computed from the corresponding bits of the inputs. The result is a number.

Logical operators (&&, ||, ! in C-family languages) operate on boolean values (true/false). They treat their operands as either "truthy" or "falsy" and return true or false. In JavaScript, 5 & 2 evaluates to 0 (bitwise AND), but 5 && 2 evaluates to 2 (logical AND short-circuits and returns the second truthy value).

I've seen plenty of production bugs caused by using bitwise AND when logical AND was intended, or vice versa. When you're writing things like if (flags & MASK) — that's a bitwise operation checking if specific bits are set. But if (condition1 && condition2) is a logical operation checking if both conditions are true at the boolean level. Different tools, different jobs.

Related Tools

XOR Calculator → Bit Shift Calculator → Binary Calculator → Binary Logic Gates → Binary Adder Circuit → Binary Translator Home →