🔢 Bitwise Calculator

Perform bitwise operations on binary numbers

How to Use This Calculator

1

Select Operation

Choose the bitwise operation you want to perform: AND, OR, XOR, or NOT. NOT is a unary operation (requires only one input), while the others are binary operations (require two inputs).

2

Enter Binary Numbers

Input the binary numbers you want to operate on. The calculator accepts only 0s and 1s. For NOT operation, enter only one number. For other operations, enter two numbers. Examples: 1010, 1100, 1111.

3

Click Calculate and Review Results

Press the "Calculate" button to perform the bitwise operation. The result shows the binary output, decimal equivalent, and a step-by-step breakdown showing how each bit position was calculated.

Formula

Bitwise operations operate on each bit position independently

AND: 1 if both are 1 | OR: 1 if either is 1 | XOR: 1 if different | NOT: flip each bit

How it works:

Bitwise operations perform logical operations on each bit position of binary numbers independently. They're fundamental to computer science, used in low-level programming, bit manipulation, and hardware design.

Truth Tables:

AND (&):

ABA&B
000
010
100
111

OR (|):

ABA|B
000
011
101
111

XOR (^):

ABA^B
000
011
101
110

NOT (~):

A~A
01
10

Example 1: 1010 AND 1100

Position 0: 0 AND 0 = 0

Position 1: 1 AND 0 = 0

Position 2: 0 AND 1 = 0

Position 3: 1 AND 1 = 1

Result: 1000 (binary) = 8 (decimal)

Example 2: 1010 XOR 1100

Position 0: 0 XOR 0 = 0

Position 1: 1 XOR 0 = 1

Position 2: 0 XOR 1 = 1

Position 3: 1 XOR 1 = 0

Result: 0110 (binary) = 6 (decimal)

Frequently Asked Questions

What's the difference between bitwise AND and logical AND?

Bitwise AND (&) operates on each bit of two numbers, returning a number. Logical AND (&&) operates on boolean values and returns true/false. For example, 5 & 3 = 1 (binary: 101 & 011 = 001), but 5 && 3 = true (both are truthy).

When are bitwise operations used in programming?

Bitwise operations are commonly used for: masking bits to extract specific values, checking and setting flags, implementing permission systems, optimizing memory by packing multiple boolean values, cryptography, graphics programming, and low-level hardware control. They're essential in systems programming and embedded systems.

What is XOR used for?

XOR (exclusive OR) is used for: swapping values without temporary variables, finding unique elements, error detection and correction, simple encryption, toggling bits, and checking if two values are different. XOR is particularly useful because A XOR A = 0 and A XOR 0 = A.

How does NOT operation work with signed numbers?

NOT flips all bits. For unsigned numbers, NOT gives the complement. For signed numbers in two's complement, NOT x = -(x + 1). For example, in 8-bit signed: NOT 5 = NOT 00000101 = 11111010 = -6. This is because -6 = -(5 + 1).

Can bitwise operations be used for optimization?

Yes! Bitwise operations are among the fastest operations in computers. They can be used to optimize: checking if a number is even (x & 1 == 0), multiplying/dividing by powers of 2 (x << n, x >> n), checking if a number is a power of 2 ((x & (x - 1)) == 0), and many other tricks.

What's the difference between XOR and OR?

OR returns 1 if either bit is 1. XOR returns 1 only if the bits are different (one is 1, the other is 0). XOR is "exclusive" - it excludes the case where both are 1. For example: 1 OR 1 = 1, but 1 XOR 1 = 0. XOR is useful when you want to detect differences or toggle bits.