Which (Java) code, library, or algorithm is best at providing similarities between bit patterns?
<p>I am after code, a library routine, or an algorithm that scores how close two different bit or boolean patterns are. Naturally if they are equal then the score should be 1, while if one is all true and the other all false then the score should 0.</p>

<p><strong>Bit pattern example</strong></p>

<p>The bit patterns that i will be testing are many times never actually equal or the same but sometimes they are very similar.</p>

<pre><code>0001 1111 0000
0000 1111 1100
0000 1110 0000
1110 0000 1111
</code></pre>

<p>In the above examples 1 &amp; 2 or 1 &amp; 3 are pretty close if i was to score them perhaps the difference would be something like 96 and 95%. On the other hand 1&amp;4 would definitely be a much lower score maybe 25%. </p>

<p>Note that bit patterns may be of different lengths but scoring should still be possible.</p>

<pre><code>001100
000011110000
</code></pre>

<p>The above two patterns would be considered identical.</p>

<pre><code>001100
00110000
</code></pre>

<p>The above two patterns would be considered close but not identical, because once "scaled" #2 is different from #1.</p>
