🔢 AND Calculator
Perform bitwise AND operations on binary numbers
How to Use This Calculator
Enter Binary Numbers
Input two binary numbers in the input fields. The calculator accepts only 0s and 1s. Examples: 1010, 1100, 1111.
Click Calculate AND
Press the "Calculate AND" button to perform the bitwise AND operation. The calculator will automatically pad shorter numbers with leading zeros to match lengths.
Review Results
The result shows both the binary AND result and the decimal equivalent. You'll also see a step-by-step comparison showing how each bit position was calculated.
Formula
AND(A, B) = A & B
Bitwise AND: Result bit is 1 only if both input bits are 1
How it works:
The AND operation compares each bit position of two binary numbers. If both bits are 1, the result is 1; otherwise, the result is 0.
AND Truth Table:
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Example 1: 1010 AND 1100
- Position 0: 0 AND 0 = 0
- Position 1: 1 AND 0 = 0
- Position 2: 0 AND 1 = 0
- Position 3: 1 AND 1 = 1
- Result: 1000 (binary) = 8 (decimal)
Example 2: 1111 AND 1010
- Position 0: 1 AND 0 = 0
- Position 1: 1 AND 1 = 1
- Position 2: 1 AND 0 = 0
- Position 3: 1 AND 1 = 1
- Result: 1010 (binary) = 10 (decimal)
Frequently Asked Questions
What is a bitwise AND operation?
A bitwise AND operation compares each bit of two binary numbers. The result is 1 only when both corresponding bits are 1. This is commonly used in programming for masking, checking flags, and low-level bit manipulation.
What happens if the binary numbers have different lengths?
The calculator automatically pads the shorter number with leading zeros to match the length of the longer number. For example, 101 AND 1100 becomes 0101 AND 1100.
When is AND operation used in programming?
AND operations are frequently used for: masking bits to extract specific values, checking if specific flags are set, implementing permission systems, and optimizing memory usage by packing multiple boolean values into a single integer.
What's the difference between logical AND (&&) and bitwise AND (&)?
Logical AND (&&) operates on boolean values and returns true/false. Bitwise AND (&) operates on individual bits of numbers and returns a number. For example, 5 && 3 returns true, but 5 & 3 returns 1 (binary 101 & 011 = 001).
Can I use AND with decimal numbers?
Yes, but the calculator converts decimal numbers to binary first. The AND operation is performed bitwise, then converted back to decimal. Enter your decimal numbers, and the calculator will show both binary and decimal representations.
What is the maximum number of bits supported?
JavaScript supports up to 53 bits for integers. For practical purposes, this calculator works well with numbers up to 32 bits (4 bytes), which covers most common use cases in programming.