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.