Open hikavdh opened 1 year ago
When I read a word from i2c, it is treated as big endian. However I want to read a temperature that is stored as little endian. I have solved this so:
BUS = SMBus(1) value = BUS.read_word_data(address, register) hstr = str(hex(value))[2:].rjust(4, '0') value = int('0x%s%s' % (hstr[2:], hstr[:2]), 16)
Not very elegant. Is there a native way to handle this?
Slow response, sorry. but you don't need to go via strings.
little_endian_value = ((value & 0xFF) << 8) | ((value >> 8) & 0xFF)
Thanks!
When I read a word from i2c, it is treated as big endian. However I want to read a temperature that is stored as little endian. I have solved this so:
Not very elegant. Is there a native way to handle this?