NUMBER THEORYBinaryMathematics Calculator
&

Bitwise AND Operation

The AND operation compares two numbers bit-by-bit, returning 1 only when both input bits are 1. It's fundamental for bit masking, subnet masks, and flag checking in computing.

Concept Fundamentals
4
Truth Table Rows
64
Max Bits
3
Formats
1
CPU Cycles

Did our AI summary help? Let us know.

IP subnet masks use AND to extract network addresses from host IPs. value & (1 << n) checks if bit n is set โ€” the fastest parity test. AND with 0 clears bits; AND with 1 preserves them.

Key quantities
4
Truth Table Rows
Key relation
64
Max Bits
Key relation
3
Formats
Key relation
1
CPU Cycles
Key relation

Ready to run the numbers?

Why: AND is used in networking (subnet masks), file permissions (Unix rwx), and hardware design (logic gates).

How: Compare each bit position: if both inputs are 1, output 1; otherwise output 0.

IP subnet masks use AND to extract network addresses from host IPs.value & (1 << n) checks if bit n is set โ€” the fastest parity test.

Run the calculator when you are ready.

Start CalculatingEnter two values in binary, decimal, or hex to perform bitwise AND
โˆง

AND Operation โ€” Bitwise Masking & Filtering

Compare bits, extract masks, check flags. Binary, decimal, hex.

๐Ÿ“Œ Examples โ€” Click to Load

For educational and informational purposes only. Verify with a qualified professional.

๐Ÿงฎ Fascinating Math Facts

๐Ÿ”’

Unix file permissions use AND: 0644 & 0444 checks read permission for all.

โ€” POSIX

๐ŸŒ

192.168.1.5 & 255.255.255.0 = 192.168.1.0 (network address).

โ€” RFC 791

๐Ÿ“‹ Key Takeaways

  • โ€ข AND truth table: 1 & 1 = 1; all other combinations = 0
  • โ€ข Masking: Use AND with 1s to extract bits, 0s to clear them
  • โ€ข Filtering: AND isolates specific bit positions (e.g., subnet masks)

๐Ÿ’ก Did You Know?

๐ŸŒIP subnet masks use AND to extract network addresses โ€” 192.168.1.5 & 255.255.255.0 = 192.168.1.0Source: RFC 791
โšกCPU ALUs perform AND in a single clock cycle โ€” one of the fastest operations in hardwareSource: Computer Architecture
๐Ÿ–ผ๏ธImage processing uses AND for masking, alpha blending, and bit-plane extractionSource: Graphics Programming
๐Ÿ”’Unix file permissions (rwx) use AND to check if a specific permission bit is setSource: POSIX
๐Ÿ”งHardware design uses AND gates as fundamental building blocks in logic circuitsSource: Digital Logic
๐Ÿ“ฆData compression uses AND for bit packing and unpacking in binary formatsSource: Data Structures

๐Ÿ“– How AND Works

The bitwise AND operation compares two numbers bit by bit. For each position, the result is 1 only if both inputs are 1; otherwise it is 0. This makes AND ideal for masking (extracting or clearing specific bits) and filtering (e.g., checking flags, subnet masks).

Truth Table

ABA AND B
000
010
100
111

๐ŸŽฏ Expert Tips

Subnet masks

Use 255.255.255.0 (or /24) to extract network from IP. Host bits become 0.

Flag checking

value & (1 << n) checks if bit n is set. Non-zero = set.

Even/odd

n & 1 === 0 means even; n & 1 === 1 means odd. Fastest parity check.

Clear lower bits

Use mask with 1s in upper bits: 0xFFF0 clears lowest 4 bits.

โš–๏ธ AND vs OR vs XOR

OperationUse Case1 & 11 & 0
ANDMasking, filtering10
ORSetting bits11
XORToggling, parity01

โ“ Frequently Asked Questions

What is the difference between logical AND (&&) and bitwise AND (&)?

Logical AND returns true/false for boolean expressions. Bitwise AND operates on each bit of two integers and returns an integer. Use && for conditions; use & for bit manipulation.

How do I check if a specific bit is set using AND?

Use value & (1 << n). If the result is non-zero, bit n is set. Example: 13 & 4 checks if bit 2 is set (13 = 1101, 4 = 0100, result = 4 = set).

How is AND used in IP subnet masking?

The subnet mask has 1s for network bits and 0s for host bits. IP & mask = network address. 192.168.1.5 & 255.255.255.0 = 192.168.1.0.

Can AND be used for even/odd detection?

Yes. n & 1 extracts the LSB. Even numbers have LSB=0, odd have LSB=1. (n & 1) === 0 means even.

What is bit masking with AND?

A mask with 1s keeps those bits, 0s clear them. 0b10111010 & 0b00001111 keeps lower 4 bits, clears upper 4.

How does AND relate to Unix file permissions?

Permissions are octal: r=4, w=2, x=1. 0644 & 0444 checks read permission for all; result 0444 means read is set.

Why use AND instead of division for bit extraction?

AND is a single CPU instruction; division is slower. AND also avoids floating-point and works on unsigned integers.

What happens with different bit lengths in AND?

Shorter values are zero-extended. 8-bit 0xFF & 16-bit 0x0F0F = 0x000F (lower byte AND).

๐Ÿ“Š Bitwise AND by the Numbers

1
Clock cycle (typical)
4
Truth table rows
64
Max bits supported
3
Formats (bin/dec/hex)

โš ๏ธ Disclaimer: This calculator is for educational and programming reference. Bitwise operations assume unsigned integers. For signed integers, behavior may differ by language. Verify results in your target environment.

๐Ÿ‘ˆ START HERE
โฌ…๏ธJump in and explore the concept!
AI

Related Calculators