title: Compute the checksum of an Intel Hex record in Python 3
body: <p>The <em>Intel Hex checksum</em> algorithm is computed by adding a string of bytes. The last byte is the two's complement of the sum of the rest of the string, so adding it to a valid string should equal zero.</p>
  
  <p><code>record_block</code> is a byte array, read in like this:</p>
  
  <pre><code>file_handle = open("branson_weld_data.txt","rb")
  ba = bytearray(file_handle.read())
  # record_block is 20 20 00 00 00 3D 25 00 00 00 2B 02 00 85 01 00 31
  # checksum is last byte, 31
  </code></pre>
  
  <p>I have not been successful in adding together the bytes of a Python byte list.</p>
  
  <pre><code>def verify_checksum(record_block):
      byte_sum = 0
      for byte in record_block:
          byte_sum &amp;= b
      return byte_sum
  
  print(verify_checksum(record_block))
      # should be zero
  </code></pre>
  
  <p>Is <code>record_block</code> a list of binary numbers? Am I adding bytes properly?</p>