Indeed, the common gotcha involves I2C motion sensors, where a pair of bytes represents a 16 bit signed integer.
Several correct ways exist to combine the 2 bytes into the intended 16 bit integer.

Originally Posted by
dave
What happen if I tried to copy and shift 8 bit registers in a ARM Architecture like in the example above?
This type of question is best answered by actually trying your code on real hardware!
Small details matter (which is why we have the "forum rule"). For example:
Code:
void setup() {
}
int calc(unsigned char H, unsigned char L) {
return (int16_t)((H<<8)+L);
}
void loop() {
Serial.println(calc(255, 255));
Serial.println(calc(4, 1));
Serial.println();
delay(1000);
}
This code prints the proper results:
However, if I try the exact same line you posted, with L & H as signed chars, the wrong result is printed.
Code:
void setup() {
}
int calc(signed char H, signed char L) {
return (int16_t)((H<<8)+L);
}
void loop() {
Serial.println(calc(255, 255));
Serial.println(calc(4, 1));
Serial.println();
delay(1000);
}
Now, I could write a lengthy message about compiler details and 2's complement number systems and sign extension. But that's not the point I wish to make.
The point is, small details like the types of the variables matter greatly. That's why we have the "forum rule" and generally try to encourage posting of complete code samples that can actually be copied into Arduino and run, rather than just code fragments, and especially code fragments that lack the types of their variables.