Skip to content

Instantly share code, notes, and snippets.

@thequbit
Created March 20, 2016 00:51
Show Gist options
  • Save thequbit/e98fa9e2c1d58fbda6e2 to your computer and use it in GitHub Desktop.
Save thequbit/e98fa9e2c1d58fbda6e2 to your computer and use it in GitHub Desktop.
# read the bytes from the I2C device
eight8 = bus.read_byte_data(address, 0x88)
eight9 = bus.read_byte_data(address, 0x89)
# get the high byte without the top bit ( sign bit )
high_byte = eight9 & 127
# get the sign bit as a 1 ( negative ) or a 0 ( possitive )
high_byte_sign = (eight9 & 128) >> 7 # get top bit
# get the low byte ( no adjustments needed )
low_byte = eight8
# generate -1 for negative, or 1 for possitive
sign = -1 if high_byte_sign == 1 else 1
# shift the high byte up by 8 bits, add the low byte, and multiply by the sign bit
dig_T1 = sign * ( (high_byte * 256) + low_byte )
print(dig_T1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment