Utility Coder
Back to Blog
calculator

AND Calculator

Andy Pham
and calculator, and calculator, and calculator online

Ready to try AND Calculator?

Access the free online tool now - no registration required

Open Tool

AND Calculator - Complete Guide

Bitwise AND calculator performs logical AND operation on binary numbers. Each bit pair is compared: 1 AND 1 = 1, all other combinations = 0. Essential for masking bits, checking flags, network subnet calculations, and low-level programming.

How It Works

Input two numbers (binary, decimal, or hex). The calculator converts both to binary, aligns them, and performs AND on each bit position. A bit in the result is 1 only if BOTH corresponding input bits are 1.

Technical Details

AND truth table: 0&0=0, 0&1=0, 1&0=0, 1&1=1. In programming: & operator (C, JavaScript, Python). Used to: clear bits (mask with 0s), test bits (mask with 1s), extract bit fields, calculate network addresses.

Common Use Cases

  1. Subnet Calculation: IP AND netmask = network address.
    • Example: 192.168.1.100 AND 255.255.255.0 = 192.168.1.0
  2. Permission Checking: Test if specific permission bits are set.
  3. Bit Masking: Extract specific bits from a value.
    • Example: value & 0xFF extracts lowest byte
  4. Even/Odd Check: n & 1 = 0 if even, 1 if odd (checks lowest bit).

Code Examples

Bitwise AND Operations

// Basic AND
console.log(12 & 10);  // 8
// 1100 (12)
// 1010 (10)
// ----
// 1000 (8)

// Check if number is even
const isEven = n => (n & 1) === 0;
isEven(4);  // true
isEven(7);  // false

// Extract lowest byte
const getLowByte = n => n & 0xFF;
getLowByte(0x1234);  // 0x34 (52)

// IP subnet calculation
function getNetworkAddress(ip, mask) {
  const ipParts = ip.split('.').map(Number);
  const maskParts = mask.split('.').map(Number);
  return ipParts.map((p, i) => p & maskParts[i]).join('.');
}
getNetworkAddress('192.168.1.100', '255.255.255.0');  // "192.168.1.0"

AND outputs 1 only where both inputs are 1. Use for masking, flag checking, and subnet calculations.

Tips & Best Practices

  • AND with 0 clears bits, AND with 1 preserves
  • Use for extracting bit fields
  • Common for subnet calculations
  • & is bitwise, && is logical
  • Result is never larger than either input

Common Mistakes to Avoid

  • Confusing & (bitwise) with && (logical)
  • Forgetting operator precedence
  • Not considering negative number representation
  • Wrong bit position counting (0-indexed)

When to Use This Tool

Use bitwise AND for subnet calculations, permission/flag checking, bit extraction, and any operation requiring selective bit clearing or testing.

Frequently Asked Questions

How does AND help with IP subnets?

IP AND mask gives network address. For 192.168.1.100/24: 11000000.10101000.00000001.01100100 AND 11111111.11111111.11111111.00000000 = 192.168.1.0. The mask zeros out the host portion.

What is bit masking?

Using AND to extract specific bits. Example: to get bits 4-7 from a byte: (value >> 4) & 0x0F. The AND with 0x0F (00001111) keeps only the lowest 4 bits.

How do I check if a bit is set?

AND with a mask having only that bit set: (value & (1 << n)) != 0 checks if bit n is set. Example: (flags & 0x04) checks bit 2.

What is the difference between & and &&?

& is bitwise AND (operates on each bit). && is logical AND (true/false only). Use & for bit manipulation, && for boolean conditions. In C: 5 & 3 = 1, but 5 && 3 = 1 (true).

Get Started

Ready to try AND Calculator? Use the tool now - it's free, fast, and works right in your browser.


Last updated: June 27, 2026

Start using AND Calculator

Free, fast, and privacy-focused - try it now

Launch Tool