XNOR calculator
Enter two values in binary, decimal or hex and get A XNOR B, bit by bit. Every bit that matches becomes 1. Pick the bit width, because with XNOR it changes the answer.
bits that match → 1 · bits that differ → 0
A 1100B 1010XNOR 1001
4-bit · 2 of 4 bits match (set to 1)
Type 0x or 0b in front of a value to mix bases. Spaces and underscores are ignored.
What XNOR does
XNOR (exclusive NOR) outputs 1 when its two inputs are the same and 0 when they are different. That makes it an equality check for single bits, and it is why XNOR is also called the equivalence gate.
| A | B | A XNOR B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Every row is the opposite of XOR, so XNOR is simply XOR followed by NOT. You will see it written in three ways:
A ⊙ B, orA ⊕ Bwith a bar over the whole thingA·B + A′·B′: “both 1, or both 0”~(A ^ B)in code
Worked example: 1100 XNOR 1010 = 1001
For numbers with several bits, XNOR works on each column separately. Take the 4-bit values 1100 (12) and 1010 (10):
Step 1: Line the bits up
Step 2: Write 1 where they match, 0 where they differ
Step 3: Read the result
Result: 1100 XNOR 1010 = 1001, or 12 XNOR 10 = 9 in 4 bits. The first and last bits match, so those are the 1s.
Why the bit width changes the answer
With XOR, leading zeros do not matter. With XNOR they do: the zeros in front of both numbers match each other, so each one becomes a 1 in the result. The same pair of numbers gives a different answer at every width:
| Width | Binary result | Decimal |
|---|---|---|
| 4-bit | 1001 | 9 |
| 8-bit | 1111 1001 | 249 |
| 16-bit | 1111 1111 1111 1001 | 65529 |
None of these is wrong; they answer different questions. Use the width of the thing you are working with: 4 bits for a nibble in a logic exercise, 8 for a byte, 32 for an int. Auto in the calculator uses the number of binary digits you typed (four bits per hex digit, and the nearest multiple of four for decimal), which is usually what a homework question means.
3-input XNOR truth table
“XNOR” with three inputs is used in two different ways, so check which one your course or simulator means. The standard gate is NOT of the 3-input XOR: it outputs 1 when an even number of inputs are 1. The other reading, “all inputs equal”, only gives 1 for 000 and 111.
| A | B | C | XNOR (even 1s) | All equal |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 1 |
A trap when wiring it: chaining two 2-input XNOR gates, (A XNOR B) XNOR C, does not give the 3-input XNOR. The two NOTs cancel and you get the 3-input XOR. Use two XOR gates and one NOT instead, or one XOR followed by one XNOR.
XNOR from other gates, and in code
If you only have basic gates, there are three common ways to build XNOR:
- AND, OR and NOT:
(A AND B) OR (NOT A AND NOT B), straight from the expression above. - Four NOR gates: G1 = A NOR B, G2 = A NOR G1, G3 = B NOR G1, output = G2 NOR G3.
- NAND gates: build XOR from four NANDs, then add a fifth NAND with both inputs joined to act as NOT.
Its most common job in hardware is an equality comparator: XNOR each pair of bits from two numbers, then AND all the outputs. The result is 1 only if every bit matched, meaning the numbers are equal.
In code there is no XNOR operator, so you write NOT of XOR. Because the NOT also flips every leading zero, mask the result to the width you want, or you get a negative number:
~(12 ^ 10) # Python and JavaScript: -7, not what you want
~(12 ^ 10) & 0xF # 4-bit: 9
~(12 ^ 10) & 0xFF # 8-bit: 249
=255-BITXOR(12,10) ' Excel has no BITXNOR; this is the 8-bit version: 249Frequently asked questions
What is 1 XNOR 1?
1. Both inputs are the same, so XNOR outputs 1. 0 XNOR 0 is 1 as well, while 1 XNOR 0 and 0 XNOR 1 are 0.
Is XNOR the same as checking for equality?
For single bits, yes: A XNOR B is 1 exactly when A equals B. For multi-bit numbers, the result is all 1s only when the two numbers are equal.
What is the difference between XOR and XNOR?
They are opposites. XOR outputs 1 when the inputs differ, XNOR when they match. Flip every bit of an XOR result and you have the XNOR result.
Is XNOR a universal gate?
No. Only NAND and NOR are universal, meaning any circuit can be built from just one of them. XNOR and XOR cannot make an AND or an OR on their own.
Sources
- MDN: Bitwise NOT (~): why ~ gives a negative number
- Python docs: unary bitwise operations: ~x equals -(x+1)
- Microsoft Support: BITXOR function: used for the Excel XNOR formula
- Wikipedia: XNOR gate: symbols, multi-input behaviour and gate constructions
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.