Xor Calculator - Bitwise XOR, Truth Table, and Result
Use this xor calculator to apply the bitwise XOR to two numbers in binary, octal, decimal, or hex at 4, 8, 12, or 16 bits, with the 2-input truth table.
Xor Calculator
Results
What Is an xor Calculator?
An xor calculator returns the bitwise exclusive-or (XOR) of two numbers by applying the XOR rule to each pair of corresponding bits. Type the two operands in binary, octal, decimal, or hex, choose a bit width, and the result panel shows the XOR in decimal, binary, octal, and hex, with the 2-input truth table right next to it. The result can exceed either input (1 XOR 2 = 3, 1 XOR 6 = 7), reaching the width's maximum (0xFF at 8 bits, 0xFFFF at 16 bits) only when every bit position differs between the operands.
- • Toggling and flipping specific bits: XOR a value with a mask that has 1s only at the positions to flip, and those bits invert while every other bit is left alone.
- • Simple symmetric encryption and checksums: The single-byte XOR cipher and many lightweight checksums rely on the fact that x XOR k XOR k returns x, so applying the same key twice undoes the operation.
- • Detecting unequal bits between two registers: XOR two register snapshots and read the bit positions that are 1 in the result to see exactly where the two values differ.
- • Boolean algebra homework and truth tables: Verify the result of a 2-input XOR expression, or work through the truth table for an exclusive-or of two Boolean variables.
The bitwise XOR is one of the four foundational bitwise operators in most languages, alongside AND, OR, and NOT, and it operates one bit at a time.
If you also need AND, OR, or NOT on the same pair of numbers, the Binary Operations Calculator runs all of the bitwise operations side by side so the results are easy to compare.
How the xor Calculator Works
The calculator parses the two inputs in the chosen base, masks each input to the bit width, applies the XOR rule column by column, and formats the result. The 2-input XOR truth table on the right is generated from the four fixed bit pairs (00, 01, 10, 11).
- A_bit_i: The bit at position i in Number 1, counted from the right starting at 0.
- B_bit_i: The bit at position i in Number 2, counted from the right starting at 0.
- result_bit_i: 1 when A_bit_i and B_bit_i differ, and 0 when they are the same.
- bitWidth: The chosen number of bits (4, 8, 12, or 16). Inputs and the result are masked to this width so high bits are dropped.
The four bit pairs that drive the truth table are always the same: 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0. A 16-bit XOR is just sixteen 1-bit XORs in a row.
Decimal 21 XOR decimal 25 (8-bit)
Number 1 = 21, Number 2 = 25, base = decimal, width = 8
21 in binary is 00010101 and 25 in binary is 00011001. Aligning them: 00010101 XOR 00011001 = 00001100.
XOR result: 12 in decimal, 00001100 in binary, 0o14 in octal, 0xC in hex.
12 = 8 + 4 marks the two bit positions where 21 and 25 disagree. Every other position had matching bits and therefore dropped to 0.
Hexadecimal 0F XOR hexadecimal F0 (8-bit)
Number 1 = 0F, Number 2 = F0, base = hex, width = 8
0F in binary is 00001111 and F0 in binary is 11110000. Aligning them: 00001111 XOR 11110000 = 11111111.
XOR result: 255 in decimal, 11111111 in binary, 0o377 in octal, 0xFF in hex.
Every bit position differs because the two nibbles are complementary, so the result is 0xFF, the largest 8-bit value.
According to MDN Web Docs, the bitwise XOR operator returns 1 in each bit position where the corresponding bits of the operands are different, and 0 only where they are the same
According to Omni Calculator, the bitwise XOR is computed by aligning two binary numbers to the right and applying the XOR rule to each pair of bits, so 10101 XOR 11001 equals 01100
To convert the inputs or the result between binary, octal, decimal, and hex without doing the math by hand, the Binary Converter accepts a value in any of those bases.
Key Concepts Behind the Bitwise XOR
Four short ideas explain why XOR behaves the way it does and how it relates to the other tools on the site. Once these are clear, XOR stops looking like a magic operator and starts looking like a column-by-column inequality test.
Logical XOR vs bitwise XOR
Logical XOR takes two Boolean values and returns true only when they differ. Bitwise XOR applies that same inequality rule to every bit position in two binary numbers, so the result is also a binary number.
Truth table for a 2-input XOR
For inputs A and B, the XOR gate outputs 1 when A and B differ, and 0 when they match. The page renders that table next to the result.
XOR in programming notation
Most languages use a single caret for bitwise XOR, written a ^ b, while logical XOR is spelled out (x xor y, ^ in Python for integers, or a dedicated operator in languages like Rust and C++).
Self-inverse property of XOR
XOR is its own inverse: x XOR x is 0 and x XOR 0 is x, so XORing a value with the same key twice restores the original. This is the property that makes XOR the basis for simple ciphers and parity checks.
The same rule extends to more than two inputs. A 3-input XOR returns 1 only when an odd number of inputs at that position are 1, which is why cascading XOR gates produces a parity output.
For full Boolean expressions that mix XOR with AND, OR, and NOT, the Boolean Algebra Calculator evaluates the expression and shows the truth table for the variables.
How to Use the xor Calculator
Enter the two operands, pick the base they are written in, and pick the bit width. The result panel updates in real time as you change the inputs.
- 1 Type Number 1 and Number 2: Enter the two operands in the first row. They must use the same base. For decimal, type digits like 21 and 25. For binary, use only 0 and 1. For hex, you can also use A through F.
- 2 Pick the input base: Use the Input Base dropdown to select 2 (binary), 8 (octal), 10 (decimal), or 16 (hexadecimal). Both operands are read in this base.
- 3 Pick the bit width: Use the Bit Width dropdown to select 4, 8, 12, or 16. Values that overflow a smaller width have their high bits dropped, like a fixed-width register.
- 4 Read the XOR result: The XOR Result (Decimal) row shows the bitwise XOR. The Binary, Octal, and Hex rows show the same value, with binary padded to the bit width and octal and hex prefixed with 0o and 0x.
- 5 Compare against the truth table: The 2-input XOR truth table next to the result shows the four (A, B) bit pairs and their outputs. Any column in a longer binary XOR follows one of those four rows.
Example: a developer wants to toggle bit 5 of the byte 0x00. They enter 0x00 in Number 1 and 0x20 in Number 2 (the mask with a single 1 at bit 5) and read 0x20 (32, 00100000, 0o40). To clear bit 5, they keep 0x20 in Number 2 and change Number 1 to 0x20, giving 0x00. Every other bit is left unchanged because the mask has 1s only at the chosen positions.
When the next step is to combine the XOR result with another value, the OR Calculator applies the bitwise OR in the same base and bit width so the comparison stays consistent.
Benefits of Using This xor Calculator
XOR is simple to define, but mixing bases and bit widths by hand is where bits go missing. The calculator keeps the operands, base, and width consistent.
- • Bit-level result without manual alignment: The result panel shows the XOR in decimal, binary, octal, and hex at the same time.
- • Works in binary, octal, decimal, and hex: Type the operands in any of the four bases and the result appears in all four.
- • Bit-width masking matches real hardware: Choose 4, 8, 12, or 16 bits to mimic a fixed-width register. Values that overflow have their high bits dropped, like an XOR with a width-sized mask in C, JavaScript, or Python.
- • Truth table next to the numeric result: The 2-input XOR truth table is rendered on the page, so the numeric answer can be verified against the four (A, B) -> output rows.
- • Reusable for toggling bits and parity checks: The same workflow covers bit toggling (x ^ mask), single-byte XOR ciphers, and parity checks where equal inputs should give 0.
The biggest practical win is consistency: XOR behaves the same way regardless of the input base, and the calculator applies that rule in one pass.
When the result is in binary and you need it in hex without doing the nibble grouping yourself, the Binary to Hexadecimal Calculator converts a binary string to its hexadecimal value in one step.
Factors That Affect the Result and Its Limits
The bitwise XOR is fixed, but four choices about the inputs change what the result means. Knowing them up front prevents surprises from signed inputs or a smaller bit width.
Input base
The base only changes how the inputs are parsed, so 0xF0 in hex and 240 in decimal produce the same bitwise XOR.
Bit width
4, 8, 12, and 16 bits set the size of the result. XOR of 0xF0 and 0x0F in 4-bit width returns 0xF (15) because the high nibble of 0xF0 is dropped to 0 and 0x0 XOR 0xF equals 0xF, not the full 0xFF you would get at 8-bit width.
Sign of the inputs
Inputs are treated as non-negative integers. For signed two's-complement values, convert to the unsigned form first and interpret the result as signed afterward.
Invalid characters for the chosen base
A digit outside the chosen base (2 in binary, G in hex) fails to parse and the result falls back to 0 until the input is corrected.
- • The calculator takes exactly two operands. For three or more inputs, XOR the first two and feed the result back in as Number 1 with the third value as Number 2, repeating until one value remains.
- • The inputs are read as non-negative integers, and the result is non-negative. For signed two's-complement integers, convert to the unsigned form, XOR, and interpret the result as signed afterward.
When the inputs and the bit width are clear, the result matches what the same operation would produce in C, Java, JavaScript, or Python.
According to Wolfram MathWorld, the exclusive-or (XOR) returns true when exactly one operand is true, and is commutative, associative, and self-inverse, so x XOR x equals 0
When you need AND, OR, XOR, NOT, and shifts on the same pair of numbers in one view, the Bitwise Calculator runs all of the bitwise operations side by side.
Frequently Asked Questions
Q: What is the xor calculator?
A: The xor calculator returns the bitwise exclusive-or (XOR) of two numbers. It accepts operands in binary, octal, decimal, or hexadecimal, applies the bit-by-bit XOR at a chosen bit width, and shows the result in decimal, binary, octal, and hex alongside the 2-input truth table.
Q: How do you compute the bitwise XOR of two numbers?
A: Write both numbers in binary, align them on the right, and apply the XOR rule to each column. The result is 1 when the two bits differ, and 0 when they match. The calculator does that for you in real time.
Q: What is the truth table of an XOR gate?
A: For two inputs A and B, the XOR gate outputs 1 when A and B differ and 0 when they are equal. The page renders that 2-input truth table directly so you can read each (A, B) row next to the numeric result.
Q: What is the difference between bitwise XOR and logical XOR?
A: Logical XOR takes two Boolean values and returns a single Boolean. Bitwise XOR applies that same inequality rule to every bit position in two integers, so the result is also an integer.
Q: Why is the XOR operation useful in programming?
A: XOR is the standard way to toggle a specific bit in a register, swap two values without a temporary, compute a parity bit, and build the single-byte XOR cipher used in many simple ciphers and checksums.
Q: How do you reverse a bit pattern with XOR?
A: XOR the value with the same key twice. Because x XOR k XOR k returns x, applying the key once encrypts or flips the bits, and applying it again restores the original value.