title: Hamming code check parity
body: <p>I am not sure if I am calculating the parity bit correctly for the the check Parity bit function I wrote.  The codeWord is 11 chars long with 4 parity bits  and 7 data bits.  Does the implementation look good?</p>
  
  <pre><code>void parityCheck(char* codeWord) {
  int parity[4] = {0}, i = 0, diffParity[4] = {0}, twoPower = 0, bitSum = 0;
  
  // Stores # of 1's for each parity bit in array.
  parity[0] = (codeWord[2] - 48) + (codeWord[4] - 48) + (codeWord[6] - 48) + (codeWord[8] - 48) + (codeWord[10] - 48);
  parity[1] = (codeWord[2] - 48) + (codeWord[5] - 48) + (codeWord[6] - 48) + (codeWord[9] - 48) + (codeWord[10] - 48);
  parity[2] = (codeWord[4] - 48) + (codeWord[5] - 48) + (codeWord[6] - 48);
  parity[3] = (codeWord[8] - 48) + (codeWord[9] - 48) + (codeWord[10] - 48);
  
  // Determines if sum of bits is even or odd, then tests for difference from actual parity bit.
  for (i = 0; i &lt; 4; i++) {
      twoPower = (int)pow((double)2, i);
  
      if (parity[i] % 2 == 0)
              parity[i] = 0;
          else
              parity[i] = 1;
  
          if ((codeWord[twoPower-1] - 48) != parity[i])
              diffParity[i] = 1;
  }
  
  // Calculates the location of the error bit.
  for (i = 0; i &lt; 4; i++) {
      twoPower = (int)pow((double)2, i);
      bitSum += diffParity[i]*twoPower;
  }
  
  
  
  // Inverts bit at location of error.
  if (bitSum &lt;= 11 &amp;&amp; bitSum &gt; 0) {
      if ((codeWord[bitSum-1] - 48)) 
          codeWord[bitSum-1] = '0';
      else
          codeWord[bitSum-1] = '1';
  }
  </code></pre>