unsigned long adc_val; //Since its a long, you can have as many bits in it as you want right?
No, C and C++ integers are fixed size. This particular one is likely to be 32 bits if I remember correctly. (It's platform dependent.)
You can do sizeof(unsigned long) and that will tell you how many characters wide the type is.
then it gets assigned 0x03 and it becomes 0b000000010000001000000011 or 0x010203
and if i try to access adc_val i will get only the 8 least significant bits
int a;
a = adc_va;
then a will be 0x03;
No, ints are 16 bits wide on Arduino. You will get 0x0203
to get the rest i will do something like:
a = adc_val >>8;
a will be 0x02;
No, it will be 0x0102
a = adc_val >> 16;
a will be 0x01;
This one is correct, but mostly by happenstance.
I dont know if this works but I will try to do it your way and see if it takes me anywhere. But then, adc_val +=api_transceiver(0); basically adding? so we will have0x01+0x02+0x03 at the end?
No, what will happen is this (keep the first one as assignment and the other 2 as plus-equals):
It gets assigned to 0x00000001 by the spi call.
It gets assigned to 0x00000100 by the <<= operator
It gets 0x00000002 added by the second spi call. The result of 0x00000100 + 0x00000002 is 0x00000102.
It gets assigned to 0x00010200 by the <<= operator
It gets 0x00000003 added by the third spi call. The result of 0x00010200 + 0x00000003 is 0x00010203.
If you want to be clearer about what's happening, you can also use |= (bitwise OR-equals).
Mathematically, they are the same.
Edit: bitwise instead of logical OR