ReadyCalcs · All calculators

Bitwise Calculator

Compare two nonnegative 16-bit integers with AND, OR and XOR operations.

INPUT & RESULT

How the result changes

-1.2511.2024
First integer (value)Current: 12 → 8

Only first integer changes; all other inputs stay at your current values. Each dot represents one whole-number input. This is not a forecast of real-world outcomes.

About this calculation

Bitwise Calculator: Compare two nonnegative 16-bit integers with AND, OR and XOR operations. Enter first integer, second integer; the reported quantities are bitwise and, bitwise or, bitwise xor. The equations and examples below show how those inputs lead to the result and where the model's assumptions matter.

Formula

AND, OR and XOR act on corresponding binary digits

Worked example

With First integer: 12, Second integer: 10, bitwise and is 8.

Method and inputs

Represent each integer as sixteen binary bits. AND yields one where both bits are one; OR yields one where either bit is one; XOR yields one where exactly one bit is one. JavaScript bitwise operators operate on 32-bit integers, and the constrained inputs keep results within a simple positive range.

Worked example

For 12 (binary 1100) and 10 (binary 1010), AND is binary 1000, or 8; OR is 1110, or 14; and XOR is 0110, or 6. Writing each number in a column makes these three results easy to verify.

A practical AND mask tests whether a selected flag is present. For instance, 12 AND 4 equals 4, so the four-bit is set in 12. Twelve AND 2 equals zero, showing that bit is absent. These checks refer to powers-of-two positions, not the written decimal digits.

How to read the result

AND is useful for checking whether selected flags are set, OR for combining flags, and XOR for finding differing bits. The decimal outputs represent whole integers even though the arithmetic is performed by aligning binary positions.

OR can set a flag without clearing existing flags; 12 OR 2 equals 14. XOR toggles a flag; applying XOR with 2 to 12 yields 14, and applying XOR with 2 again returns 12. These reversible properties offer a quick way to test the output by hand.

Assumptions and checks

Only nonnegative integers from zero through 65,535 are accepted. Negative numbers introduce signed two’s-complement representation, which depends on a chosen bit width and is deliberately outside this form.

Do not confuse XOR with exponentiation: the caret operator in many programming languages means exclusive OR. Decimal digits are not compared independently; values are first encoded in binary. If a displayed result seems unfamiliar, convert all operands to base two.

Common questions

What does the bitwise calculator calculate?

It gives the AND, OR and XOR results for the two integers using the same bit positions. These are exact discrete operations within the stated input range.

When should I recalculate or check another method?

Recheck the chosen bit width before applying a mask in software or hardware. A wider protocol field may have leading bits beyond this calculator’s sixteen-bit input limit.

Inputs

  • First integer
  • Second integer

Related calculators