I wired up a TMP102 sensor(on a breakout board) from sparkfun. The wiring made sense, standard i2c wiring. Here is the TMP102's datasheet. I used this guide as a guide for the program that I wrote. The program that is running on the particle photon(the microcontroller board that I am using), has a confusing line of code. The line of code that I am referring to does this: The bits of the MSB that are received by the microcontroller(Most significant byte, not bit) are shifted left, 8 times and then Or'ed with the LSB(least significant byte). The bits of the result are then shifted right 4 times. Lastly, the whole thing is multiplied by 0.0625. This line of code sums up what I just said, and can be seen in the guide linked above:
int temp = ((( MSB << 8) | LSB) >> 4) * 0.0625;
I got everything to work(it measures temperature), but I don't know why it works. My question is: why is the above line of code required? Why do these operations need to be completed?. And as a side question, if the bits in a byte are shifted left 8 times, wouldn't that result in a value of 0000 0000? If my question is a bit vague, please tell me.