My program is reading a sensor in I2C that puts out 2 bytes (msb & lsb) of a 16 bit number in 2's complement.
The 16 bit number is scaled by dividing it by 4096.
This is my code, line 58 is the (else:) line:
Code: Select all
if msb > 0x7F: #if bit7=1 (negative): do 2's complement
data16 = ~((msb << 8) | lsb) #1st do 1's complement
data16 +1= #then add 1
else:
data16 = (msb << 8) | lsb
data16 /= 4096 #finally, div result by 4096
Code: Select all
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 58
SyntaxError: invalid syntax
>>>