Skip to content
Math

AND Calculator - Bitwise AND Operation

Enter two integers in decimal, binary (prefix 0b), or hexadecimal (prefix 0x) to compute their bitwise AND. The result appears in decimal, binary, hexadecimal, and octal simultaneously. The step panel shows every bit position side by side so you can trace exactly how each output bit is determined.

Your details

Enter any non-negative integer in decimal (60), binary with a 0b prefix (0b111100), or hex with a 0x prefix (0x3C).
Enter any non-negative integer in decimal, binary (0b...), or hex (0x...). Must be in the range 0 to 4,294,967,295 (32-bit unsigned).
Controls how many bit positions are shown in the binary outputs and the step panel.
Result (decimal)Non-zero result
12

A AND B expressed as a standard base-10 integer

Result (binary)00001100
Result (hex)0xC
Result (octal)0o14
A in binary00111100
B in binary00001101
A in decimal60
B in decimal13
A (decimal)60
B (decimal)13
A AND B12

60 AND 13 = 12

  • Out of 8 bit positions, 4 are set in A and 3 are set in B.
  • The AND result has 2 set bits - only positions where both A and B had a 1.

Next stepUse the step panel below to trace each bit position. For multi-value AND chains, apply AND repeatedly: (A AND B) AND C.

What is a bitwise AND operation?

A bitwise AND compares two integers one bit at a time. For each bit position, the output bit is 1 only when both input bits are 1. If either input bit is 0, the output is 0. This rule mirrors logical multiplication: 1 multiplied by 1 is still 1, but anything multiplied by 0 is 0. The symbol for AND in formal logic is the wedge (A), in electronics a centered dot or the label NAND/AND on a gate diagram, and in C-family programming languages the single ampersand (&) for bitwise AND and double ampersand (&&) for logical AND.

How to calculate bitwise AND by hand

Convert both numbers to binary and right-align them so their least-significant bits are in the same column. Then go column by column from right to left: write 1 if both bits are 1, write 0 otherwise. For example, 60 AND 13: 60 in binary is 0011 1100 and 13 is 0000 1101. Working left to right: bits 7 to 4 are 0 AND 0 = 0, then bit 3 is 1 AND 1 = 1, bit 2 is 1 AND 1 = 1, bit 1 is 0 AND 0 = 0, bit 0 is 0 AND 1 = 0. The result is 0000 1100, which is 12 in decimal.

Common uses of bitwise AND

Bit masking is the most common application. To test whether bit k of a number n is set, compute n AND (1 shifted left k places): a non-zero result means bit k is 1. To keep only the lower 8 bits of a value, AND it with 255 (0xFF). Network engineers use AND with a subnet mask to extract the network address from an IP address: for example, 192.168.1.45 AND 255.255.255.0 = 192.168.1.0. In software, feature flags, permission systems, and hardware register manipulation all rely heavily on AND to read or clear specific bits without disturbing the others.

Three-input AND and chaining multiple values

The AND rule extends naturally to more than two inputs: the output is 1 only when every single input is 1. In hardware, a three-input AND gate has eight possible input combinations (2 to the power 3) and produces 1 for exactly one of them, 1 AND 1 AND 1 = 1. In software you chain the operation: (A AND B) AND C. The result is the same regardless of which pair you evaluate first because AND is both commutative (A AND B equals B AND A) and associative ((A AND B) AND C equals A AND (B AND C)).

AND gate truth table (single bit)

Bit ABit BA AND B
00 0
01 0
10 0
11 1

The AND operation returns 1 only when both input bits are 1. All other combinations produce 0.

Frequently asked questions

What does the AND operator do?

The AND operator compares two binary numbers bit by bit. At each position it outputs 1 only when both corresponding input bits are 1. All other combinations (0 AND 0, 0 AND 1, 1 AND 0) produce 0. In Boolean algebra the AND operation is equivalent to multiplication: 1 times 1 is 1, and anything times 0 is 0.

How do I calculate 5 AND 3?

5 in binary is 101 and 3 is 011. Comparing bit by bit from right: bit 0 is 1 AND 1 = 1, bit 1 is 0 AND 1 = 0, bit 2 is 1 AND 0 = 0. The result is 001, which equals 1 in decimal. So 5 AND 3 = 1.

What is the difference between & and && in programming?

In C, C++, Java, and JavaScript, a single ampersand (&) is the bitwise AND operator: it compares integers bit by bit and returns an integer result. A double ampersand (&&) is the logical AND operator: it evaluates two Boolean (true/false) expressions and returns true only if both are true. This calculator uses the bitwise form.

Can I use this calculator with hexadecimal or binary input?

Yes. Prefix binary values with 0b (for example, 0b1101) and hexadecimal values with 0x (for example, 0xFF). The calculator parses all three bases automatically and shows the result in decimal, binary, hexadecimal, and octal at the same time.

Why is the result sometimes 0?

The result is 0 when A and B share no common set bits - that is, every position where A has a 1, B has a 0, and vice versa. Such values are called bitwise disjoint or mutually exclusive in the bit sense. For example, 5 (101) AND 2 (010) = 0 because the two numbers have no overlapping 1-bits.

What is an AND gate in electronics?

An AND gate is a basic digital logic component with two or more input lines and one output line. It applies the AND truth table to its inputs. When all inputs carry a high voltage (logic 1), the output is high. If any input is low (logic 0), the output is low. AND gates can be built from NAND gates or NOR gates and are the building blocks of arithmetic logic units, multiplexers, and decoders in computer processors.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…