Binary AND
Perform bitwise AND operations on binary numbers. Free Binary AND Calculator with step-by-step results and truth tables.
String 1
String 2
Output
Result
What is Binary AND?
The Binary AND operation is a fundamental bitwise function used in computer science and digital electronics. It compares two binary digits (bits) and produces a result of 1 (true) only if both input bits are 1. If either or both inputs are 0, the result is 0.
This operation forms the basis for many low-level computing tasks, including masking, logic gates, and network addressing.
How Binary AND Works
The operation works by comparing the bits of two numbers position by position, starting from the least significant bit (rightmost).
Truth Table
The following truth table shows the output of the AND operation for all possible input combinations:
| Input A | Input B | Result (A AND B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Calculation Example
Let's perform a Binary AND operation on two 8-bit numbers: 10101100 and 11001010.
- Align the numbers vertically.
- Compare the bits in each column.
- Write
1if both bits are1; otherwise, write0.
10101100 (Operand 1)
& 11001010 (Operand 2)
----------
10001000 (Result)
In this example, only the 4th and 8th bits (from the right) are 1 in both operands, so they remain 1 in the result. All other bits become 0.
Common Applications
The Binary AND operation is not just theoretical; it has practical uses in various fields of technology.
1. Network Subnetting
In networking, the AND operation is used to determine the network address from an IP address and a subnet mask.
- IP Address:
192.168.1.1(11000000.10101000.00000001.00000001) - Subnet Mask:
255.255.255.0(11111111.11111111.11111111.00000000) - Operation: IP
ANDMask = Network Address (192.168.1.0)
2. Bit Masking (Clearing Bits)
Programmers use AND to "mask" or turn off specific bits in a byte while leaving others unchanged. For example, to ensure the last 4 bits of a number are 0, you can AND it with 11110000.
3. Checking Parity or Odd/Even Status
You can check if a binary number is odd or even by ANDing it with 1.
- If
(Number & 1) == 0, the number is even. - If
(Number & 1) == 1, the number is odd.
Frequently Asked Questions
What is the difference between Binary AND and Logical AND?
Binary AND (&) operates on individual bits of two numbers (e.g., 101 & 011 = 001). Logical AND (&&) operates on boolean values (true/false) and determines if the entire statement is true (e.g., true && false = false).
Is the Binary AND operation commutative?
Yes, the operation is commutative. A AND B produces the same result as B AND A. It is also associative, meaning (A AND B) AND C is equal to A AND (B AND C).
Can I use this calculator for hexadecimal or decimal numbers?
Yes. While the operation is fundamentally binary, this calculator supports inputting values in Hexadecimal, Decimal, and Octal. It converts them to binary, performs the AND operation, and can convert the result back to your preferred format.
Why is the result always smaller or equal to the operands?
Since the AND operation requires both bits to be 1 to produce a 1, it can never "create" new 1s that weren't present in the original numbers. It acts as a filter, removing bits that aren't shared, which results in a value less than or equal to the smallest operand.
References
- MDN Web Docs. "Bitwise AND (&)". Mozilla Developer Network. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND
- Khan Academy. "Bitwise operators". Computer Science. https://www.khanacademy.org/computing/computer-science