Bitwise XNOR Calculator (Bit Equality) – Free

This bitwise XNOR calculator compares two binary words column by column and writes 1 where the bits match and 0 where they differ.

How to use the Bitwise XNOR Calculator tool

  1. Enter the first word in Input A, for instance 1100.
  2. Enter the word to compare against in Input B, for instance 1010.
  3. Select Calculate to run the comparison.
  4. Look at the Result box: 1001 for the sample values. Each 1 marks a column where the inputs are equal.
  5. Select Copy to copy the bits. Select Example to restore the sample inputs and rerun them.

XNOR: the equivalence operation

XNOR is the complement of XOR. XOR answers the question of whether two bits are different, and XNOR answers whether they are the same. The output is 1 for the pairs 0,0 and 1,1, and 0 for the pairs 0,1 and 1,0. Logic texts also call it equivalence or coincidence.

The tool computes the XOR of the two inputs, inverts it, and keeps as many bits as the longer input has.

A B | A XNOR B
0 0 | 1
0 1 | 0
1 0 | 0
1 1 | 1

Bitwise XNOR example: comparing two bytes

Compare 10110010 with 10100010. The two bytes differ in one position, bit 4.

A result made only of ones means the words are identical: 10110010 XNOR 10110010 is 11111111. Any 0 pinpoints a mismatch. Hardware equality comparators work this way, with one XNOR gate per bit pair feeding a wide AND gate.

      10110010   (Input A)
XNOR  10100010   (Input B)
   =  11101111

Mind the width: padded zeros count as matches

The shorter input is padded on the left with zeros up to the length of the longer one. A padded 0 that lines up with a 0 in the other word is a match and produces 1. So 0101 XNOR 101 is 1111, and 101 XNOR 11000 is 00010.

If you are checking whether two values are equal, that is the behavior you want. If you are modeling a fixed register, type both operands with all their leading zeros so the width is explicit. Each field accepts 1 to 65,536 binary digits, and spaces or a 0b prefix are ignored.

Where XNOR appears

XNOR is less visible than AND or OR in source code, but it sits at the center of several circuits and algorithms.

  • Equality comparators in CPUs, address decoders and cache tag matching.
  • Binarized neural networks, where multiplying values of +1 and -1 is replaced by XNOR followed by a population count.
  • Linear feedback shift registers with XNOR feedback, where all zeros is a valid state and all ones is the lock-up state.
  • Software checks written as ~(a ^ b), masked to the word size, to find the bits two values share.

Frequently asked questions

What is 1100 XNOR 1010?

The result is 1001. The first and last columns hold equal bits (1,1 and 0,0), so they give 1. The two middle columns differ and give 0.

How do I calculate XNOR in code?

Write ~(a ^ b) in C, Java, JavaScript or Python. Because the inversion also flips the unused high bits, mask the answer to your word size, for example ~(a ^ b) & 0xFF. This page masks to the length of the longer input.

Is XNOR the same as checking equality?

For a single bit, yes: XNOR is 1 exactly when the two bits are equal. For multi-bit words the values are equal only if every result bit is 1. Any 0 in the output marks a differing position.

How does XNOR relate to Hamming distance?

The number of zeros in the XNOR result is the Hamming distance between the two words, and the number of ones is the count of matching positions. For 10110010 and 10100010 the result 11101111 has one zero, so the distance is 1.

Why is XNOR sometimes written as NXOR or ENOR?

They are alternative names for one gate. XNOR and NXOR both mean an XOR with an inverted output, and ENOR is short for exclusive NOR. All of them share the truth table shown on this page.

Does XNOR give the same result if I swap the inputs?

Yes. XNOR is commutative, so A XNOR B equals B XNOR A. Inverting one input turns XNOR into XOR, and inverting both leaves it unchanged.

Related tools