MPU-6050 doubt in playgroud code Arduino.cc

I am studying the MPU-6050 and saw this article. I'm wondering in two lines of code.

http://playground.arduino.cc/Main/MPU-6050

This line from what I understand the shield guard reading the last value in this register and the source code is asking these values. That's right?

Wire.requestFrom(MPU,14,true);


This code I understood that he reads the values, but because moving bits to the left?

AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)


The line

Wire.requestFrom(MPU,14,true);


initiates a read transfer using I2C. The read consists of two 8 bit values, which are then joined together into a single 16 bit value:

AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)


That basically means "Read one byte, shift it left 8 bits, read a second byte, and OR the two values together".

So if the first byte is (in binary) 0b00100100 and the second is 0b10101010 then the result would be 0b0010010010101010.

In hexadecimal that would be taking 0x24, shifting it left to 0x2400, then or-ing 0xAA with it, to form 0x24AA.

In decimal it would be taking the number 36, shifting it left 8 bits to make it 9216, then or-ing 170 to make 9386.

• The operator | is not the OR operator? Reference: arduino.cc/en/Reference/BitwiseAnd – Tiedt Tech Dec 3 '14 at 13:21
• That is correct. | = or, & = and, << = left shift, >> = right shift – Majenko Dec 3 '14 at 13:32
• Therefore do not understand the code. Because it reads the first value and moves 8 bits and then does the OR. Trying to find out the reason for this. – Tiedt Tech Dec 3 '14 at 13:37
• But I have told you what it does. What don't you understand about it? – Majenko Dec 3 '14 at 13:44
• Because that is how you join two 8 bit values into a 16 bit value. – Majenko Dec 3 '14 at 15:32