Bitwise Calculator

Apply AND, OR, XOR or shifts to two integers.

Technology and NetUpdated 2026-11-201 min read
Bitwise Calculator
Used only for left and right shift.
Decimal result
...
Binary result...
First operand in binary...
Second operand in binary...

What it does

Bitwise operators work directly on the binary digits of integers. They are used for masking, packing flags, fast arithmetic by powers of two and many low level algorithms.

University of Alaska Fairbanks computer science notes describe AND as a mask, OR as reassembling bit fields, XOR as controlled inversion and shifts as moving bits to higher or lower places.

The page gives small examples such as 3 AND 5 equals 1, which corresponds to 0011 AND 0101 equals 0001.

This tool applies one chosen operation to two nonnegative integers and shows the result in decimal and binary, together with both operands in binary.

The operations use 32 bit unsigned arithmetic, which matches the usual behaviour for these operators in many languages.

How to use

  1. Enter two nonnegative whole numbers.
  2. Choose AND, OR, XOR, left shift or right shift.
  3. For shifts, set the shift amount.
  4. Read the decimal and binary results.
  5. Check both operands in binary to follow the operation bitwise.
  6. Try 12 and 10 with AND to get 8.

Formula

AND: bits set in both. OR: bits set in either. XOR: bits set in exactly one. Left shift by n multiplies the first operand by 2^n; right shift divides by 2^n with truncation.
a, b
The two integer operands.
n
Shift amount for shift operations.
bit
A single binary digit, 0 or 1.
mask
Using AND with zeros to clear unwanted bits.

The engine coerces results to unsigned 32 bit values. It rejects negative operands and fractional inputs rather than applying language specific conversions.

Worked example

Example: masking with AND

Operands 12 and 10 with the AND operation.

  1. 12 in binary is 1100 and 10 in binary is 1010.
  2. Comparing bit by bit, only the third bit is set in both.
  3. The result is 1000 in binary, which is 8 in decimal.
  4. The tool reports result 8 and binary 1000.
  5. Using OR instead gives 1110, or 14.
  6. Using XOR gives 0110, or 6.

Reference table

Results for operands 12 and 10
OperationBinaryDecimal
AND10008
OR111014
XOR01106
Left shift 12 by 211000048

Limits

  • Operands are limited to 0 through 4294967295.
  • Shifts use up to 31 positions.
  • The tool uses 32 bit unsigned arithmetic.
  • It handles integers only, not floating point bit patterns.

Common mistakes

  • Entering negative numbers and expecting two's complement behaviour.
  • Using the second operand for a shift when only the first is shifted.
  • Confusing XOR with OR when both bits are set.
  • Expecting right shift to preserve sign, which unsigned arithmetic does not.
  • Forgetting that a shift amount of zero changes nothing.

Try it yourself

Quick checks. Answers sit tucked under each question.

What is 12 AND 10?

8, because 1100 AND 1010 equals 1000.

What does left shift by 2 do to 12?

It gives 48, since 1100 shifted two places is 110000.

Which operation keeps bits set in exactly one operand?

XOR.

Questions

What are bitwise operators?

Operations that act on individual binary digits of integers.

What is AND used for?

Masking out bits by combining with zeros.

What does XOR do?

It sets a bit when exactly one input bit is set.

How does left shift relate to multiplication?

Shifting left by n multiplies by two to the power n.

Why 32 bit unsigned?

It matches common language behaviour for these operators.

Can I use negative numbers?

Not on this page. Operands must be nonnegative.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.