XOR Calculator – Logical & Bitwise Exclusive OR

Compute logical XOR and bitwise XOR for up to 4 inputs — see truth tables, parity checks, bit-by-bit visualization, binary/hex output, and swap tricks.

XOR Result (Decimal)
255
170 XOR 85
Result (Binary)
0b11111111
8-bit binary representation
Result (Hex)
0xFF
Hexadecimal representation
Input A (Binary)
0b10101010
Decimal: 170 | Hex: 0xAA
Input B (Binary)
0b01010101
Decimal: 85 | Hex: 0x55
Double XOR Check
170
(A XOR B) XOR B should equal A (170): ✓ Verified
Self-XOR
0
A XOR A always equals 0 (cancellation property)
Bit Width
8-bit
Set bits: A=4, B=4, Result=8

Bit-by-Bit Visualization

b7
1
0
XOR
1
b6
0
1
XOR
1
b5
1
0
XOR
1
b4
0
1
XOR
1
b3
1
0
XOR
1
b2
0
1
XOR
1
b1
1
0
XOR
1
b0
0
1
XOR
1
🔵 Input A🟡 Input B🟢 Result

Bit Breakdown Table

Bit PositionABA XOR B
Bit 7101
Bit 6011
Bit 5101
Bit 4011
Bit 3101
Bit 2011
Bit 1101
Bit 0011

XOR Truth Table Reference

ABA XOR B
000
011
101
110

XOR Properties

PropertyExpression
CommutativeA XOR B = B XOR A
Associative(A XOR B) XOR C = A XOR (B XOR C)
IdentityA XOR 0 = A
Self-inverseA XOR A = 0
Double XOR(A XOR B) XOR B = A
ComplementA XOR 1…1 = NOT A
Swap tricka^=b; b^=a; a^=b swaps a and b
ParityXOR of N bits = 1 if odd number of 1s
Planning notes, formulas, and examples

About the XOR Calculator – Logical & Bitwise Exclusive OR

The XOR (exclusive OR) operation is one of the most versatile and powerful operations in computing and discrete mathematics. Unlike regular OR which returns true when at least one input is true, XOR returns true only when the inputs differ — exactly one is true and the other is false. This "difference detector" property makes XOR invaluable across cryptography, error detection, data structures, and algorithm design.

At the bitwise level, XOR compares each corresponding pair of bits in two integers. A result bit is 1 only when the two input bits differ. This leads to remarkable properties: XOR-ing any number with itself produces zero (self-cancellation), XOR-ing with zero returns the original number (identity), and applying XOR twice with the same value restores the original (involution). These properties enable the famous XOR swap algorithm that exchanges two variables without a temporary, and they form the mathematical backbone of one-time pad encryption — the only theoretically unbreakable cipher.

Multi-input XOR acts as a parity function: the result is 1 when an odd number of inputs are 1. This is the basis of parity bits in error detection, RAID storage (XOR across disks for redundancy), and CRC checksums. This calculator supports up to four inputs in both logical and bitwise modes, with configurable bit widths from 4 to 32 bits, colour-coded bit-by-bit visualisation, and comprehensive property tables.

When This Page Helps

XOR is deceptively simple — one bit at a time — but tracking all 8, 16, or 32 bit positions by hand invites errors, and chaining three or four inputs compounds the risk. This calculator shows the binary representation of every operand, aligns the bits vertically, and highlights which positions differ. It supports 2–4 inputs in both logical and bitwise modes, so you can explore parity, self-cancellation (A ⊕ A = 0), and multi-input XOR together. Cryptography and networking students use it to verify XOR-cipher steps and RAID parity calculations.

How to Use the Inputs

  1. Choose between Bitwise XOR and Logical XOR mode.
  2. Select the number of inputs (2, 3, or 4) for multi-input parity checks.
  3. For bitwise mode, pick a bit width (4, 8, 16, or 32 bits).
  4. Enter integer values for each input, or click a preset button.
  5. View the XOR result in decimal, binary, and hex along with the bit-by-bit visualisation.
  6. Check the double-XOR verification and self-XOR properties.
  7. In logical mode, observe the parity (odd/even count of TRUE inputs).
  8. Reference the truth table and properties table for study.
Formula used
A XOR B: output is 1 when inputs differ (A=0,B=1 or A=1,B=0). Bitwise XOR applies this per bit. Multi-input XOR = parity function (1 if odd number of 1-bits).

Example Calculation

Result: 255 (0xFF)

170 = 10101010, 85 = 01010101. Every bit position differs, so XOR yields 11111111 = 255.

Tips & Best Practices

  • XOR with all 1s (e.g., 0xFF for 8-bit) flips every bit — equivalent to bitwise NOT.
  • XOR swap works without a temp variable: a^=b; b^=a; a^=b.
  • Multi-input XOR is 1 when an odd number of inputs are 1 — use for parity checks.
  • In cryptography, XOR is the core of one-time pads and stream ciphers.
  • A XOR A = 0 always — useful for finding the unique element in arrays.
  • XOR is its own inverse: if C = A XOR B, then A = C XOR B.

How XOR Differs from OR

Both OR and XOR return 1 when at least one input is 1, but XOR returns 0 when both inputs are 1. This single-row difference in the truth table gives XOR its distinctive properties: it detects difference rather than presence. In a truth table, OR yields (0,1,1,1) while XOR yields (0,1,1,0) for inputs (0,0), (0,1), (1,0), (1,1).

Self-Inverse, Parity, and the XOR Swap

XOR is its own inverse: A ⊕ B ⊕ B = A, because XOR-ing with B toggles bits and doing it again toggles them back. This makes XOR the foundation of simple encryption (one-time pads, stream ciphers) and the classic temp-free swap trick (a^=b; b^=a; a^=b). For multiple inputs, XOR computes the parity function — the result is 1 when an odd number of inputs are 1 — which is the basis for RAID parity, CRC error detection, and Hamming codes.

XOR in Cryptography and Algorithms

In a one-time pad, XOR-ing plaintext with a truly random key of equal length produces ciphertext that is information-theoretically unbreakable. Block ciphers like AES use XOR at every round to mix key material into the data. In algorithms, XOR is used to find the single unique element in an array (XOR everything together; duplicates cancel), to generate pseudo-random sequences (LFSR), and to implement Gauss–Jordan elimination over GF(2).

Sources & Methodology

Last updated:

Frequently Asked Questions

  • OR returns true when at least one input is true (including when both are true). XOR returns true only when the inputs differ — exactly one is true. In a truth table, OR gives 1,1,1,0 while XOR gives 0,1,1,0.