title: CRC32 calculation in Python without using libraries
body: <p>I  have been trying to get my head around CRC32 calculations without much success, the values that I seem to get do not match what I should get.</p>
  
  <p>I am aware that Python has libraries that are capable of generating these checksums (namely zlib and binascii) but I do not have the luxury of being able to use them as the CRC functionality do not exist on the micropython.</p>
  
  <p>So far I have the following code:</p>
  
  <pre><code>import binascii
  import zlib
  from array import array
  
  poly = 0xEDB88320
  
  table = array('L')
  for byte in range(256):
      crc = 0
      for bit in range(8):
          if (byte ^ crc) &amp; 1:
              crc = (crc &gt;&gt; 1) ^ poly
          else:
              crc &gt;&gt;= 1
          byte &gt;&gt;= 1
      table.append(crc)
  
  def crc32(string):
      value = 0xffffffffL
  
      for ch in string:
          value = table[(ord(ch) ^ value) &amp; 0x000000ffL] ^ (value &gt;&gt; 8)
  
      return value
  
  teststring = "test"
  
  print "binascii calc:  0x%08x" % (binascii.crc32(teststring) &amp; 0xffffffff)
  print "zlib calc:      0x%08x" % (zlib.crc32(teststring) &amp; 0xffffffff)
  print "my calc:        0x%08x" % (crc32(teststring))
  </code></pre>
  
  <p>Then I get the following output:</p>
  
  <pre><code>binascii calc:  0xd87f7e0c
  zlib calc:      0xd87f7e0c
  my calc:        0x2780810c
  </code></pre>
  
  <p>The binascii and zlib calculations agree where as my one doesn't.  I believe the calculated table of bytes is correct as I have compared it to examples available on the net.  So the issue must be the routine where each byte is calculated, could anyone point me in the correct direction?</p>
  
  <p>Thanks in advance!</p>