AND Calculator

Compute the bitwise AND of two whole numbers, bit by bit: see the result in decimal, binary, and hexadecimal, plus how many bits they share.

Quick Facts

Rule
Each result bit is 1 only when both input bits are 1
AND compares A and B one binary digit at a time.
Identity
A AND 0 = 0; A AND (all 1s) = A
ANDing with 0 clears bits; ANDing with a mask of 1s keeps them.

Your Results

Calculated
A AND B
-
Decimal result
Binary result
-
Zero-padded to bit width
Hexadecimal result
-
Base-16 representation
Shared set bits
-
Bit positions where both are 1

Ready

Enter two whole numbers and a bit width, then press Calculate.

How the AND Calculator works

This tool computes the bitwise AND of two whole numbers. Bitwise AND compares two numbers one binary digit (bit) at a time: the result has a 1 in a given position only if both numbers have a 1 in that same position, and a 0 everywhere else. It is one of the four fundamental logic operations in computing, alongside OR, XOR, and NOT.

Formula and method

For each bit position, the result bit follows a simple rule: result = 1 only when both A and B have a 1 in that position; otherwise the result bit is 0. That gives the single-bit truth table 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 0 = 0, 1 AND 1 = 1. To compute A AND B for whole numbers, write both numbers in binary padded to the same length, then apply this rule to every column independently. For example, 12 (1100 in binary) AND 10 (1010 in binary) gives 1000 in binary, which is 8 in decimal — a 1 survives only in the column where both numbers had a 1.

Common sources of error

  • Bit width too small: a number that does not fit the selected bit width is rejected rather than silently truncated — choose 16-bit or 32-bit for larger values.
  • Confusing AND with OR: AND requires both bits to be 1; OR only requires one. Swapping them produces the wrong mask or filter.
  • Misreading bit order: bit 0 is the rightmost (least significant) bit, not the leftmost, in standard binary notation.

Checking your result

A quick sanity check: A AND B can never be larger than the smaller of A and B, because AND only ever clears bits — it never sets a bit that was not already 1 in both operands. If a computed result exceeds min(A, B), something is wrong. You can also verify small examples by hand: write both numbers in binary, align the columns, and AND each column individually.

Applications

Bitwise AND is used throughout computing: masking out unwanted bits, testing whether a specific flag or permission bit is set, extracting a color channel from a packed value, checking whether a number is even (n AND 1 equals 0 for even numbers), and computing a network address from an IP address and subnet mask.

Frequently Asked Questions

What does bitwise AND do?
Bitwise AND compares two numbers bit by bit. Each bit in the result is 1 only when the matching bit in both numbers is 1; otherwise the result bit is 0.
How is bitwise AND different from logical AND?
Logical AND (&&) combines two true/false values and returns a single boolean. Bitwise AND (&) operates on the binary digits of numbers and returns a number, comparing every bit position independently.
What is a bitmask and how does AND use it?
A bitmask is a number with 1s in the positions you want to keep and 0s in the positions you want to clear. ANDing a value with a mask keeps only the bits where the mask has a 1, which is how flags and permission bits are extracted.
Can this calculator handle negative numbers?
This tool treats both inputs as non-negative integers represented in plain binary up to the selected bit width (8, 16, or 32 bits). Negative numbers require two's complement representation, which is outside the scope of this calculator.