Working on an I2C project and came across this statement in the code:
temperature |= (ushort)(ow.ReadByte() << 8); // MSB
Would someone explain to me how this works? From what I can find it is a bitwise operator but I have no experience in this area.
Thanks
ow.ReadByte() << 8
means that you take the byte ( = 8Bits) and shift them 8 bits to the left
Sample bitmask 16 bit
0000 0000 1111 1111
after the statement its
1111 1111 0000 0000
As others have said, it basically shifts the byte read by 8 bits to the left, and then copies it into the high byte of temperature, leaving any other bits that are set the way they are.