I am trying to read-in two separate, 3 byte messages over CAN, add them together, and send back out over CAN, on a CANBED V1 which uses a Leonardo.
My confusion is using bit shifting.
If I attempt to shift 1 by 1..14 bits I seem to understand,
uint32_t hdbs = 1 << (14) ;
Serial.println(hdbs, BIN);
this codes gives me 100000000000000 in the display window if printing binary or 16384 decimal.
But if I try a bit shift of 15 or more
uint32_t hdbs = 1 << (15) ;
Serial.println(hdbs, BIN);
I am now confused as I get
11111111111111111000000000000000 or 4294934528 in decimal
What basic concept am I missing? I tried using unsigned long, long, etc.,
If I do some simple math and use hdbs = 8 * 4095 I get the correct answer of 32760, but when I try 8*4096 I get 4294934528, which should be 32768 (which seems like would exceed a 16 bit unsigned, but I thought I was declaring hdbs as a 32 bit variable.