AND Calculator

Calculate the bitwise AND of two numbers.

Result: A AND B

Enter both values to see the result in decimal, hex, binary, and octal.

AND truth table
ABA AND B
000
010
100
111

AND Calculator – Bitwise AND

Calculate the bitwise AND of two integers and see the result in decimal, hex, binary, and octal. Enter the values in any format – 200, 0xC8, 0b11001000, or 0o310 – and the calculator lines up the bits so you can see exactly which positions survive. For example 12 AND 10 = 8, because 1100 AND 1010 = 1000.

How the AND operation works

AND returns 1 only when both bits are 1; in every other case the result bit is 0. It is applied to every bit position of the two numbers independently and is written a & b in C, Java, JavaScript, Python, Go, and most other languages.

Masking – the main use of AND

AND is the standard way to extract or test bits with a mask. Bits that are 1 in the mask are kept, bits that are 0 are cleared:

  • value & 0xFF keeps the lowest byte of a number.
  • (value & 0x04) != 0 tests whether bit 2 is set.
  • color & 0x00FF00 isolates the green channel of a 24-bit RGB color.
  • ip & netmask gives the network address – 192.168.1.77 & 255.255.255.0 = 192.168.1.0 (see the CIDR Calculator).
  • n & (n - 1) clears the lowest set bit; if the result is 0, n is a power of two.
  • n & 1 is 1 for odd numbers and 0 for even numbers.

Reading the result

The aligned view shows operand A, operand B, and the result bit by bit, grouped in nibbles. The results table lists the unsigned and signed (two's complement) decimal value, hexadecimal, binary, and octal forms, each with a copy button. The truth table next to it summarises the rule for single bits.

Bit width

In Auto mode the width is the smallest multiple of 8 bits that fits both values. Fix the width to 8, 16, 32, 64, or 128 bits to mimic a specific integer type; negative numbers are then converted to two's complement, so -1 & 0xFF gives 255. Related tools: OR Calculator, NAND Calculator, and the all-in-one Bitwise Calculator.

Frequently Asked Questions

2. In binary 110 AND 011 = 010 – only the middle bit is 1 in both numbers.

AND the value with a mask that has only that bit set. If the result is not zero, the bit is set. For bit 3 use 8 (0b1000): 13 & 8 = 8, so bit 3 of 13 is set.

The network address of an IP is the IP ANDed with the subnet mask. For 10.1.2.3 with mask 255.255.0.0 the network is 10.1.0.0.