Created
March 20, 2016 00:51
-
-
Save thequbit/e98fa9e2c1d58fbda6e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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