Main Site Documentation

Logical OR assignment


#1

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


#2

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


#3

Good examples here : http://www.informit.com/articles/article.aspx?p=23210&seqNum=3 :slight_smile:


#4

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.


#5

Thanks