Accelerometer reading

Hi guys

I recently bought an accelrometer and want to make a simple program that reads out the values in G’s. I followed an online tutorial but i doesnt understand why the done this

readx = bus.read_byte_data(addr, OUT_X_L)
readx2 = bus.read_byte_data(addr, OUT_X_H)

x = readx | readx2 << 8

if x > 32767 :
x -= 65536

If sorry for the simple question but why do you need to sum the 2 values and then bit shift it 8 places?
and I assume the second part checks to see if the value is in range.

(In range of a 16 bit output)

thanks for the help

Your sensor returns a 16 number and your program combines the two bytes to an integer in the range +/- 2^15
It's correct

The two values are not summed, that | is a bitwise OR, see also this tutorial.

why do you need to sum the 2 values and then bit shift it 8 places?

The order of operator precedence in C/C++ is to shift first, then OR.

When in doubt, or for clarity, use parentheses.

int value = x_low | (x_high<<8);