How to use the Bitwise AND Calculator tool
- Type the first binary number into Input A, for example 1100.
- Type the second binary number, usually your mask, into Input B, for example 1010.
- Select Calculate, or select Example to load 1100 and 1010 and run them.
- Read the AND result in the Result box. It has as many digits as the longer input.
- Select Copy to copy the result, or Clear to empty both inputs.
How bitwise AND works
AND compares two numbers one bit position at a time. The output bit is 1 only when the bit in Input A and the bit in Input B are both 1. Any position where either input holds a 0 produces a 0.
Because a 0 in one operand always forces a 0 in the result, the second operand works as a filter. Positions where the mask has a 1 pass through unchanged, and positions where it has a 0 are cleared. That is why AND is the standard way to read part of a value.
Bitwise AND example: masking the low nibble
Suppose a status byte is 10110110 and you only care about its lowest four bits. AND it with the mask 00001111. The upper four bits are cleared and the lower four are copied through.
The same idea extracts a network address. The last octet 10000010 (130) ANDed with the /26 mask octet 11000000 (192) gives 10000000, which is 128, the start of that subnet.
10110110 (Input A)
& 00001111 (Input B)
= 00000110Input format and word size
Both fields accept only the digits 0 and 1. A leading 0b prefix and any spaces are removed first, so 0b1100 1010 reads as 11001010. Each input can hold from 1 to 65,536 binary digits. Anything else returns the message Enter between 1 and 65,536 binary digits.
The inputs do not need to be the same length. The tool takes the longer one as the word size and pads the shorter one with zeros on the left. For AND this means every position beyond the shorter input comes out as 0: 11110000 AND 1010 gives 00000000, because 1010 is read as 00001010. The result always keeps leading zeros so its width matches the word size.
Common uses of AND in code
Masking with AND is one of the most frequent bit operations in systems and network code. Typical jobs include these.
- Testing a flag: 10110101 AND 00100000 returns 00100000, so bit 5 is set.
- Checking for an odd number: AND with 1 keeps only the lowest bit.
- Clearing bits: lowercase a (01100001) AND 11011111 gives uppercase A (01000001).
- Wrapping an index in a power-of-two buffer, where index AND (size - 1) replaces a modulo.
Frequently asked questions
What is the bitwise AND of 1100 and 1010?
The result is 1000. Only the leftmost position has a 1 in both numbers, so only that bit survives. In decimal this is 12 AND 10, which equals 8.
What is the difference between bitwise AND and logical AND?
Bitwise AND, written & in C, Java, JavaScript and Python, works on every bit and returns a number. Logical AND, written && or and, treats each operand as a single true or false value. For example 4 & 2 is 0, while 4 && 2 counts as true.
Can I AND two binary numbers of different lengths?
Yes. The shorter number is padded with zeros on the left until it matches the longer one. Since AND with 0 is always 0, the extra high bits of the result are 0. Pad a mask with ones yourself if you want to keep those upper bits.
Can I enter decimal or hexadecimal values?
No. This calculator accepts binary digits only. Convert the values first with the Decimal to Binary or Hexadecimal to Binary tool, then paste the binary strings into Input A and Input B.
How do I check whether a specific bit is set?
Put a mask with a single 1 at that position in Input B. If the result is all zeros, the bit is clear. If the result equals the mask, the bit is set. For bit 5 of an 8-bit value the mask is 00100000.