0

I've got this simple question that i can't crack. I do a readout from a chip that gives med MSB and LSB using SMBus in Python2.7.

I need to remove the 2 first bit in MSB and then combine it with the last 8 bit fron LSB.

Like:

MSB = bus.read_byte_data(address, register_1)
LSB = bus.read_byte_data(address, register_2)

MSB = 11110000 , LSB = 11111111

MSB_cut = 110000 , LSB = 11111111

Combined = 11000011111111

And then convert it to an integer.

I have tried with Bitwise operation but i don't get it right. I know this it quit simple, so is there someone who can show med the right code?

Thanks.

RAJensen
  • 65
  • 1
  • 8

1 Answers1

0

Okay

i've createt this really ugly solution:

MSB = bus.read_byte_data(adress, register_1)
LSB = bus.read_byte_data(adress, register_2)
mb = bin(MSB)
lb = bin(LSB)
tot = mb[4:] + lb[2:]
total = int(tot, 2)

I think there must a more delicate way to this. :-)

RAJensen
  • 65
  • 1
  • 8