How to use the Binary neural network Calculator tool
- Enter the first bit string in First binary vector, using only the digits 0 and 1.
- Enter a string of the same length in Second binary vector. Spaces are ignored, so you can group bits.
- Select Calculate, or select Example to run 101101 against 101001.
- Read XNOR matches and Bipolar dot product in the result, and select Copy to reuse them.
How a binary neural network computes a dot product
In a binarized layer, weights and activations are limited to +1 and -1, so each fits in one bit: 1 for +1 and 0 for -1. Multiplying two such values gives +1 when the bits are equal and -1 when they differ. That is the XNOR truth table.
A neuron's weighted sum is then a count. If s of the n bit positions match, the sum is s x (+1) plus (n - s) x (-1), which simplifies to 2s - n. Hardware and optimized libraries do this with one XNOR and one population count per machine word, replacing n multiplications. This tool reports s as XNOR matches and 2s - n as the bipolar dot product.
Worked example with 101101 and 101001
Compare the strings position by position. They agree at positions 1, 2, 3, 5 and 6 and differ at position 4, so there are 5 matches out of 6. The dot product is 2 x 5 - 6 = 4. Expanding by hand confirms it: the products are +1, +1, +1, -1, +1, +1, and they add up to 4.
First: 101101
Second: 101001
XNOR matches: 5 of 6
Bipolar dot product: 4Reading the two result lines
The match count and the dot product carry the same information on two scales.
- The dot product ranges from -n to +n, where n is the vector length.
- It equals n when the vectors are identical and -n when one is the bitwise complement of the other.
- It always has the same parity as n, so an odd-length pair can never give 0.
- The Hamming distance between the vectors is n minus the match count.
- A binarized neuron outputs +1 when the dot product meets its threshold and -1 otherwise. This tool stops at the sum and applies no threshold or bias.
Input rules and the error message
Each field must contain at least one digit and only 0 and 1. Whitespace is stripped before the comparison, so 1011 0010 and 10110010 are the same vector. Commas, signs and literal -1 or +1 values are not accepted. If either field breaks these rules, or the lengths differ, the tool shows Enter two equal-length binary vectors. The code sets no maximum length.
Where XNOR and popcount arithmetic is used
Binarized networks such as BinaryNet and XNOR-Net use this arithmetic for inference on microcontrollers and FPGAs, where one 64-bit XNOR and a popcount instruction handle 64 weights at once. The same match count underlies Hamming-distance search over binary embeddings and hash codes.
Frequently asked questions
Why does 0 represent -1 in a binary neural network?
A bit has two states and a binarized weight has two values, so one is mapped to the other with value = 2 x bit - 1. With that mapping, multiplication of values turns into XNOR of bits, which is far cheaper than arithmetic.
What is the XNOR popcount formula?
For two n-bit vectors, dot product = 2 x popcount(XNOR(a, b)) - n. The popcount is the number of positions where the bits agree. This calculator prints that count as XNOR matches and the final value as Bipolar dot product.
How do I get the Hamming distance from the result?
Subtract the match count from the length. In the 101101 and 101001 example there are 5 matches of 6, so the Hamming distance is 1. The dot product also equals n minus twice the Hamming distance.
Can the two vectors have different lengths?
No. A dot product pairs each element with one partner, so the tool rejects unequal lengths. It does not pad the shorter string, because it cannot know where the missing bits belong.
Does this calculator run a full binarized network?
No. It evaluates one dot product, which is the pre-activation sum of a single neuron. Bias, batch normalization, the sign activation and multiple layers are outside its scope.