Calculating 0's and 1's in PHP
<p>I want to calculate Frequency (Monobits) test in PHP:</p>

<blockquote>
  <p>Description: The focus of the test is
  the proportion of zeroes and ones for
  the entire sequence. The purpose of
  this test is to determine whether that
  number of ones and zeros in a sequence
  are approximately the same as would be
  expected for a truly random sequence.
  The test assesses the closeness of the
  fraction of ones to ½, that is, the
  number of ones and zeroes in a
  sequence should be about the same.</p>
</blockquote>

<p>I am wondering that do I really need to calculate the 0's and 1's (the bits) or is the following adequate:</p>

<pre><code>$value = 0;

// Loop through all the bytes and sum them up.
for ($a = 0, $length = strlen((binary) $data); $a &lt; $length; $a++)
    $value += ord($data[$a]);

// The average should be 127.5.
return (float) $value/$length;
</code></pre>

<p>If the above is not the same, then how do I exactly calculate the 0's and 1's?</p>
