NEW
Also known as: AND
A bitwise operation producing 1 only when both input bits are 1.
DESCRIPTION
Binary AND performs a conjunction operation on each bit position of two operands, yielding 1 only when both corresponding bits are 1. It is widely used for masking, flag checks, and implementing logical predicates at the bit level. In hardware, AND is a fundamental logic gate with simple, fast implementations. Correct use of AND masks avoids unintended bit leakage and improves performance. It pairs conceptually with OR and XOR in bit manipulation tasks.
ALTERNATIVE DEFINITIONS
Wikipedia
A bitwise AND takes two equal-length binary representations and performs the logical AND operation on each pair of corresponding bits.
Explains per-bit behavior with equal-length operands.
NIST
A Boolean operator that yields TRUE if and only if all its operands are TRUE.
Formal Boolean definition applicable to bitwise operations at per-bit level.
RELATED TERMS
Binary XOR Binary Math Boolean Algebra Bitwise Operation Logic Gate Masking Bit Mask Truth Table Predicate
COMPETING TERMS
RELATIONS
- Broader: Binary Math Bitwise Operation
KNOWLEDGE AREAS
Mathematics Software Engineering
TARGET AUDIENCE
Software Developer Data Engineer Hardware Engineer
EXTERNAL SOURCES
- Wikipedia - Bitwise operation
- cppreference - C operators including bitwise AND (&).
- Microsoft - C# bitwise AND and shift operators.
TOP QUESTIONS
What is Binary AND used for?
Common uses include bit masking, permission checks, and extracting specific bits from a value without altering others.
Category: Application
How does Binary AND differ from Binary OR?
AND requires both bits to be 1 to produce 1, whereas OR produces 1 if at least one bit is 1. AND is often used for masking.
Category: Comparison
What is a typical mistake with Binary AND?
Using AND instead of OR when combining flags can clear bits unintentionally. Verify with truth tables before coding.
Category: Mistakes
How do I create a mask with Binary AND?
Set mask bits to 1 where you want to keep value bits; value & mask preserves only those bits.
Category: How To
Does Binary AND short-circuit like logical AND?
Bitwise AND computes all bits and does not short-circuit; logical AND may short-circuit in high-level languages.
Category: Misunderstanding
Is Binary AND commutative and associative?
Yes, AND is both commutative and associative, enabling reordering and grouping of operations.
Category: Concept
How is Binary AND implemented in hardware?
As an AND gate per bit, often within ALUs, providing very low-latency operations.
Category: Concept
Where does Binary AND appear in cryptography?
It appears in masking, bit slicing, and constant-time routines to avoid branching side channels.
Category: Application
How can I test Binary AND logic?
Use unit tests with representative masks and construct truth tables for edge cases like all-zeros and all-ones inputs.
Category: Testing