I know I'm missing something so simple here, but I can't figure it out.
If I do char letter = 'A'; then letter = letter << 8, letter = 0, as one should expect, since we are shifting the bits "off the shelf" to the left.
But, if we do this:
char letter = 'A';
void setup()
{
Serial.begin(9600);
int twoBytes = letter << 8;
Serial.println(twoBytes, BIN);
}
void loop() {}
The result is 100000100000000, but why? << has precedence over =, so it should be bitshifting letter left by 8 first, then assigning that value (which should be 0) to twoBytes.
int twoBytes = 0;- the fact that you didn't implies that you expect letter to be treated as 16 bits. – Nick Gammon Sep 20 '23 at 06:05letterto be in high byte oftwoBytes, and I'm putting another char into the low byte oftwoBytes. Even though the code I wrote worked, being the inquisitive person I am I realized it didn't make sense, hence the question. – AJ_Smoothie Sep 20 '23 at 15:00