title: Calculate Modulo 256 Checksum in PHP
body: <p>I've searched Stackoverflow already and unfortunately nothing came up. I am working with the FIX protocol and I need to generate a Modulo 256 checksum as described at <a href="http://fixwiki.fixprotocol.org/fixwiki/CheckSum" rel="nofollow">http://fixwiki.fixprotocol.org/fixwiki/CheckSum</a>.</p>
  
  <pre><code>$count = strlen($message);
  $count = $count % 256;
  $checksum = 256 - $count;
  
  if(strlen($checksum) == 1) {
      $checksum = '00' . $checksum;   
  }
  
  if(strlen($checksum) == 2) {
      $checksum = '0' . $checksum;    
  }
  </code></pre>
  
  <p>Using the FIX string of:</p>
  
  <p>8=FIX.4.2|9=42|35=0|49=A|56=B|34=12|52=20100304-07:59:30</p>
  
  <p>It should return:</p>
  
  <p>8=FIX.4.2|9=42|35=0|49=A|56=B|34=12|52=20100304-07:59:30|10=185|</p>
  
  <p>However my script returns:</p>
  
  <p>8=FIX.4.2|9=42|35=0|49=A|56=B|34=12|52=20100304-07:59:30|10=199|</p>
  
  <p>I'd be grateful if someone could point me in the right direction!</p>