title: Join two hex integers in Python
body: <p>I am only new to Python, and currently reading 2 bytes from a digital compass using I2C on the Raspberry Pi. The MSB and LSB values are being stored in an array e.g.<br>
  <code>a = [0x07, 0xFF]</code></p>
  
  <p>I would like to join these two bytes into one variable such as<br>
  <code>b == 0x07FF</code>  </p>
  
  <p>How would I go about doing this?<br>
  I thought it would be as easy as multiplying the MSB by 256 and adding it to the LSB but I keep getting "IndexError: list index out of range"<br>
  Any help on this would be appreciated :)</p>
  
  <p>My code is:  </p>
  
  <pre><code>import smbus
  import time
  
  bus = smbus.SMBus(1)
  
  addr = 0x1E
  
  bus.write_byte_data(addr, 0x00, 0x70)
  bus.write_byte_data(addr, 0x01, 0xA0)
  bus.write_byte_data(addr, 0x02, 0x00)
  time.sleep(0.006)
  
  for i in range(0,10):
      x = bus.read_i2c_block_data(addr,0x03,2)
      y = bus.read_i2c_block_data(addr,0x07,2)
      z = bus.read_i2c_block_data(addr,0x05,2)
  
      xval = 256*x[2]+x[1]
      print x, y, z
      print xval
      time.sleep(1)
  print 'exiting...'
  </code></pre>
  
  <p>The error I get is:  </p>
  
  <pre><code>Traceback (most recent call last):
    File "compass2.py", line 18, in &lt;module&gt;
      xval = 256*x[2]+x[1]
  IndexError: list index out of range
  </code></pre>