title: Creating xor checksum of all bytes in hex string In Python
body: <p>While attempting to communicate with an audio processing device called BSS London Blu-80, I discovered I have to send a checksum created by Xoring the message.  An example message being sent would be:</p>
  <pre><code>0x8d 0x1e 0x19 0x1b 0x83 0x00 0x01 0x01 0x00 0x00 0x00 0x4b 0x00 0x00 0xc2
  </code></pre>
  <p>With 0xc2 being the correct checksum for that message.</p>
  <p>&quot;The checksum is a single-byte exclusive or(xor) of all the bytes in the message body.&quot;</p>
  <p>The message body is that above minus the checksum.</p>
  <p>The code I attempt however:</p>
  <pre><code>packet = '0x8d 0x1e 0x19 0x1b 0x83 0x00 0x01 0x01 0x00 0x00 0x00 0x4b 0x00 0x00'
  xor = 0
  i = 0
  while i &lt; len(packet):
      xor = xor ^ ord(packet[i])
      i += 1
  
  &gt;&gt;print xor
  46
  &gt;&gt;print hex(xor)
  '0x2e'
  </code></pre>
  <p>Any help will be appreciated.</p>