And Calculator

Bitwise AND Calculator

Perform bitwise AND operations on binary numbers with detailed bit-by-bit analysis.

2026-05-12T10:30:55.101Z
Decimal: 12
Decimal: 10

AND Operation Result

Bit-by-Bit AND Operation
Number 1:00001100
Number 2:00001010
AND Result:00001000
Each bit is 1 only if both input bits are 1, otherwise 0
Decimal
8
Binary
00001000
Hexadecimal
0x8
AND Truth Table
Bit A
Bit B
A AND B
0
0
0
0
1
0
1
0
0
1
1
1

What is Bitwise AND?

Bitwise AND is a binary operation that compares two numbers bit by bit. For each pair of corresponding bits, the result is 1 only if both bits are 1; otherwise, the result is 0. It's represented by the & operator in most programming languages.

The AND operation is fundamental in computer science, digital logic, and low-level programming. It's used for bit masking, flag checking, permission systems, network subnet calculations, and graphics programming. Understanding bitwise operations is essential for writing efficient code and working with hardware interfaces.

For example, 12 & 10 in binary is 1100 & 1010 = 1000, which equals 8 in decimal. Each bit position is compared: the result has a 1 only where both input numbers have a 1.

How to Use the AND Calculator

Step-by-Step Process:

  1. Choose your input mode: Decimal, Binary, or Hexadecimal
  2. Enter the first number in your chosen format
  3. Enter the second number in the same format
  4. View the bit-by-bit comparison showing how AND works
  5. See results in decimal, binary, and hexadecimal formats
  6. Reference the truth table to understand the logic

Common Use Cases:

  • Bit Masking: Extract specific bits from a value (e.g., value & 0xFF gets lowest 8 bits)
  • Flag Checking: Test if specific bits are set (e.g., flags & READ_FLAG)
  • Even/Odd Testing: number & 1 returns 1 if odd, 0 if even
  • Network Subnets: Calculate network addresses from IP and subnet masks
  • Clearing Bits: Use AND with inverted masks to clear specific bits

Example

Real-World Scenario: File Permission Check

In Unix/Linux systems, file permissions are stored as bits. Let's check if a file has read permission (value 4 in decimal, 100 in binary).

File permissions:
6 (decimal) = 110 (binary) = read + write
Read permission flag:
4 (decimal) = 100 (binary)
Check: 6 & 4
110 (file permissions)
100 (read flag)
---
100 = 4 (has read permission!)

Result: Since 6 & 4 = 4 (non-zero), the file has read permission. This technique is used throughout operating systems and permission management.

Frequently Asked Questions

What's the difference between & (AND) and && (logical AND)?

& is bitwise AND that compares individual bits, while && is logical AND that treats entire values as true/false. Bitwise AND works on each bit; logical AND returns a boolean.

When would I use bitwise AND in programming?

Common uses include checking flags, extracting specific bits (bit masking), testing even/odd numbers, calculating network addresses, optimizing performance-critical code, and working with hardware registers or embedded systems.

How do I check if a number is even using AND?

Use number & 1. If the result is 0, the number is even; if 1, it's odd. This works because even numbers always have 0 in the least significant bit.

What is bit masking?

Bit masking uses AND to extract or isolate specific bits. For example, value & 0xFF extracts the lowest 8 bits by ANDing with a mask of all 1s in those positions.

Can I use AND on negative numbers?

Yes. JavaScript represents negative numbers internally using 32-bit two's complement notation. When you perform AND on a negative number, the calculator displays the full 32-bit representation so the bit-by-bit operation is mathematically accurate. Positive numbers are shown with 8 bits for clarity.

Why is my binary result showing leading zeros?

The calculator displays 8 bits (1 byte) to show the full bit pattern. This helps visualize how the AND operation works on each bit position. Leading zeros are significant in bitwise operations.

What other bitwise operations exist?

Besides AND, there are OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). Each has specific uses in programming, with AND being particularly useful for masking and flag checking.

Is bitwise AND faster than regular arithmetic?

Yes, bitwise operations are typically very fast as they're direct CPU instructions. They're often used in performance-critical code, though modern compilers optimize well, so clarity should usually come before micro-optimization.

Related Tools